package com.mission.schedule.activity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.appwidget.AppWidgetManager;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.AssetFileDescriptor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Rect;
import android.media.MediaPlayer;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.text.Editable;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.view.inputmethod.InputMethodManager;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.google.gson.Gson;
import com.lcf.refreshlibrary.ILoadingLayout;
import com.lcf.refreshlibrary.PullToRefreshBase;
import com.lcf.refreshlibrary.PullToRefreshScrollView;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.mission.schedule.CommonDialog.CalenderNoteDialog;
import com.mission.schedule.CommonDialog.CalenderNoteEditChildMenuDialog;
import com.mission.schedule.CommonDialog.CalenderNoteEditRightMenuDialog;
import com.mission.schedule.CommonDialog.CalenderRingDialog;
import com.mission.schedule.CommonDialog.NoteEditChildMenuDialog;
import com.mission.schedule.CommonDialog.NoteEditRightMenuDialog;
import com.mission.schedule.R;
import com.mission.schedule.add603.bean.UpNew;
import com.mission.schedule.annotation.ViewResId;
import com.mission.schedule.applcation.App;
import com.mission.schedule.bean.CalenderNoteBean;
import com.mission.schedule.bean.CalenderNoteSynBean;
import com.mission.schedule.bean.qd606.NoteTitleDetailBean;
import com.mission.schedule.bean.qd606.UploadImageBean;
import com.mission.schedule.clock.QueryAlarmData;
import com.mission.schedule.constants.Const;
import com.mission.schedule.constants.ShareFile;
import com.mission.schedule.constants.URLConstants;
import com.mission.schedule.cutimage.Crop;
import com.mission.schedule.entity.CLRepeatTable;
import com.mission.schedule.entity.ScheduleTable;
import com.mission.schedule.my160920.widget.CButton;
import com.mission.schedule.my160920.widget.CheckBoxC;
import com.mission.schedule.my160920.widget.EditTextC;
import com.mission.schedule.my160920.widget.TextViewC;
import com.mission.schedule.service.DownImageService;
import com.mission.schedule.service.DownRepeatService;
import com.mission.schedule.service.LocalSynService;
import com.mission.schedule.service.NoteService;
import com.mission.schedule.sinaadd.BaseDialog;
import com.mission.schedule.utils.AfterPermissionGranted;
import com.mission.schedule.utils.CalendarChange;
import com.mission.schedule.utils.CharacterUtil;
import com.mission.schedule.utils.DateUtil;
import com.mission.schedule.utils.EasyPermissions;
import com.mission.schedule.utils.ImageUtils;
import com.mission.schedule.utils.MyLinearLayout;
import com.mission.schedule.utils.NetUtil;
import com.mission.schedule.utils.NetUtil.NetWorkState;
import com.mission.schedule.utils.PathFromUriUtils;
import com.mission.schedule.utils.PhotoActionHelper;
import com.mission.schedule.utils.ProgressUtil;
import com.mission.schedule.utils.ReadTextContentXml;
import com.mission.schedule.utils.RxPhotoUtils;
import com.mission.schedule.utils.ScreenUtil;
import com.mission.schedule.utils.SharedPrefUtil;
import com.mission.schedule.utils.StringUtils;
import com.mission.schedule.utils.Utils;
import com.mission.schedule.view.CycleWheelView;
import com.mission.schedule.view.ScrollLinearLayout;
import com.mission.schedule.widget.SwipeLinearLayout;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXMiniProgramObject;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.tencent.mm.sdk.platformtools.Util;
import com.yalantis.ucrop.UCrop;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;

@SuppressLint({"SimpleDateFormat", "HandlerLeak"})
public class CalenderNoteEditActivity extends BaseActivity implements OnClickListener, EasyPermissions.PermissionCallbacks, EditTextC.EdittextCoutomListener {

    @ViewResId(id = R.id.top_ll_back)
    private LinearLayout top_ll_back;
    @ViewResId(id = R.id.myschedule_title)
    private TextView myschedule_title;
    @ViewResId(id = R.id.my_friend_ll_right)
    private RelativeLayout my_friend_ll_right;
    @ViewResId(id = R.id.copy)
    private TextView copy;
    @ViewResId(id = R.id.px)
    private TextView px;
    @ViewResId(id = R.id.sty)
    private TextView sty;
    @ViewResId(id = R.id.note_edit_view)
    private EditTextC editTextC;
    @ViewResId(id = R.id.note_edit_list)
    private LinearLayout mEditTextList;
    @ViewResId(id = R.id.bottom_ll)
    private ScrollLinearLayout bottom_ll;
    @ViewResId(id = R.id.header_image)
    private ImageView header_image;
    //    @ViewResId(id = R.id.image_line)
//    private View image_line;
    @ViewResId(id = R.id.scrollview)
    private PullToRefreshScrollView scrollview;
    //    @ViewResId(id = R.id.xiala_tishi_tv)
//    private TextView xiala_tishi_tv;
//    @ViewResId(id = R.id.guoqi_img)
//    private ImageView guoqi_img;
    @ViewResId(id = R.id.calender_sing)
    private TextView calender_sing;
    @ViewResId(id = R.id.calender_tixing)
    private TextView calender_tixing;
    @ViewResId(id = R.id.calender_time)
    private TextView calender_time;
    @ViewResId(id = R.id.calender_week)
    private TextView calender_week;
    @ViewResId(id = R.id.share)
    private TextView share;
    @ViewResId(id = R.id.calender_date)
    private TextView calender_date;
    @ViewResId(id = R.id.shun)
    private CheckBoxC shun;
    @ViewResId(id = R.id.o_ll)
    private LinearLayout o_ll;
    @ViewResId(id = R.id.time_ll)
    private LinearLayout time_ll;
    @ViewResId(id = R.id.date_ll)
    private LinearLayout date_ll;
    @ViewResId(id = R.id.shun_ll)
    private LinearLayout shun_ll;
    Context context;

    String time, userid, ringdesc, ringcode, remark = "0", remark1 = "0";
    String addcopy = "1";
    String addicon = "0";
    int id = 0, openState = 0;

    SharedPrefUtil sharedPrefUtil = null;
    Map<String, String> mMap;
    List<CalenderNoteBean.PageBean.ItemsBean> list = new ArrayList<>();
    private String Title = "", Title2 = "";
    //是否是新建日程
    boolean isNewList = false;
    int stylee = 0;
    int type = -1;
    String other1 = "0";
    String lingshengnames = "完成任务", lingshengcode = "g_88";
    String schTime = "11:11";
    int schBeforeTime = 0;
    String schRepeatID = "0", schRepeatID2 = "0";
    boolean isRepeatEidt = false;
    boolean isCopyChild = true;
    String schRemark1 = "0";
    int copyisAlarm = 1;
    int newopeartType = 0;

    @Override
    protected void setListener() {
        top_ll_back.setOnClickListener(this);
        my_friend_ll_right.setOnClickListener(this);
        copy.setOnClickListener(this);
        px.setOnClickListener(this);
        sty.setOnClickListener(this);
//        header_image.setMaxHeight(ScreenUtil.getScreenPix(context).heightPixels);
        header_image.setOnClickListener(this);
        header_image.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                isLongJTImage = 1;
                setHeaderImage();
                return true;
            }
        });
//        calender_date.setOnClickListener(this);
        time_ll.setOnClickListener(this);
        calender_sing.setOnClickListener(this);
        calender_tixing.setOnClickListener(this);
        date_ll.setOnClickListener(this);
        shun_ll.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (shun.isChecked()) {
                    shun.setChecked(false);
                    schIsPostpone = 0;
                } else {
                    shun.setChecked(true);
                    schIsPostpone = 1;
                }
            }
        });
        share.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.ISNEWYOUKE, "0").equals("-1")) {
                    isShare = false;
                    upLoadData();
                } else {
                    VipDailog();
                }
            }
        });
        bottom_ll.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Log.e("TAG", bottom_ll.getY() + "");
            }
        });
//        shun.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                if (shun.isChecked()) {
//                    schIsPostpone = 0;
//                } else {
//                    schIsPostpone = 1;
//                }
//            }
//        });
    }

    private void VipDailog() {
        final android.app.AlertDialog builder = new android.app.AlertDialog.Builder(context).create();

        builder.show();
        Window window = builder.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        params.alpha = 0.92f;
        window.setAttributes(params);// 设置生效
        window.setContentView(R.layout.dialog_alter);
        TextView delete_ok = (TextView) window.findViewById(R.id.delete_ok);
        delete_ok.setText("注册");
        delete_ok.setTextColor(Color.RED);
        delete_ok.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent newt = new Intent(context, PhoneCodeLoginActivity.class);
                newt.putExtra("type", 1);
                newt.putExtra("login", true);
                context.startActivity(newt);
            }
        });
        TextView cancle_tv = (TextView) window.findViewById(R.id.cancle_tv);
        cancle_tv.setText("忽略");
        cancle_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                builder.dismiss();
            }
        });
        TextView delete_tv = (TextView) window.findViewById(R.id.delete_tv);


        delete_tv.setText("该功能是正式用户功能\n请注册正式用户");

    }

    String maxTitleId = "0";
    String path = "";
    InputMethodManager imm;
    String name = "";
    String schID = "";

    public static String Today() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date(System.currentTimeMillis());
        return simpleDateFormat.format(date);
    }

    public static String Week(String date) {
        String week = "周日";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date today = null;
        try {
            today = simpleDateFormat.parse(date);
            Calendar c = Calendar.getInstance();
            c.setTime(today);
            int weekday = c.get(Calendar.DAY_OF_WEEK);
            switch (weekday) {
                case 1:
                    week = "周日";
                    break;
                case 2:
                    week = "周一";
                    break;
                case 3:
                    week = "周二";
                    break;
                case 4:
                    week = "周三";
                    break;
                case 5:
                    week = "周四";
                    break;
                case 6:
                    week = "周五";
                    break;
                case 7:
                    week = "周六";
                    break;
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return format(today) + " " + week;
    }

    public static String format(Date d) {
        long datel;
        String days = "今天";
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String da = formatter.format(new Date());
        try {
            Date ad = formatter.parse(da);
            if (ad.compareTo(d) == 0) {
                days = "今天";
            } else if (new Date().before(d)) {
                datel = (d.getTime() - new Date().getTime()) / 1000;
                long day = datel / (60 * 60 * 24);
                if (day == 0) {
                    days = "明天";
                } else {
                    days = (day + 1) + "天后";
                }

            } else {
                datel = (new Date().getTime() - d.getTime()) / 1000;
                long day = datel / (60 * 60 * 24);
                if (day == 0) {
                    days = "昨天";
                } else {
                    days = (day + 1) + "天前";
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return days;
    }

    @Override
    protected void onResume() {
        super.onResume();
//        if (other1 != null) {
//            if (other1.equals("1")) {
//                guoqi_img.setVisibility(View.VISIBLE);
//            } else {
//                guoqi_img.setVisibility(View.GONE);
//            }
//        }
//
//        if (App.getDBcApplication().getNoteTitleother1(maxTitleId)) {
//            guoqi_img.setVisibility(View.VISIBLE);
//        } else {
//            guoqi_img.setVisibility(View.GONE);
//        }
    }

    @Override
    protected void setContentView() {
        setContentView(R.layout.calender_edit_list);
    }

    @TargetApi(Build.VERSION_CODES.M)
    @Override
    protected void init(Bundle savedInstanceState) {
        context = this;
        editTextC.setEditTitle();
        imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        sharedPrefUtil = new SharedPrefUtil(context, ShareFile.USERFILE);
        userid = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERID, "");
        time = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.ALLTIME, "08:58");
        name = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERNAME, "");
        String suntype = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.SHUNYANTYPE, "1");
        lingshengnames = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.MUSICDESC, "完成任务");
        lingshengcode = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.MUSICCODE, "g_88");
        isNewList = getIntent().getBooleanExtra("newadd", false);
        newopeartType = getIntent().getIntExtra("newopeartType", 0);
        if (sharedPrefUtil.getBoolean(ShareFile.ISHUN, false)) {
            suntype = "1";
            sharedPrefUtil.putBoolean(ShareFile.ISHUN, false).commit();
        }
        if (!isNewList) {
            maxTitleId = getIntent().getStringExtra("schSourceDesc");
            Title2 = Title = getIntent().getStringExtra("content");
            lingshengnames = getIntent().getStringExtra("lingshengnames");
            calender_sing.setText(lingshengnames);
            lingshengcode = getIntent().getStringExtra("lingshengcode");
            isAlarm = StringUtils.getIsIntEqulesNull(Integer.valueOf(getIntent().getStringExtra("schIsAlarm")));
            copyisAlarm = isAlarm;
            schTime = getIntent().getStringExtra("schTime");
            calender_date.setText(getIntent().getStringExtra("schDate"));
            schBeforeTime = StringUtils.getIsIntEqulesNull(Integer.valueOf(getIntent().getStringExtra("schBeforeTime")));
            schDisplayTime = StringUtils.getIsIntEqulesNull(Integer.valueOf(getIntent().getStringExtra("schDisplayTime")));
            schIsPostpone = StringUtils.getIsIntEqulesNull(Integer.valueOf(getIntent().getStringExtra("schIsPostpone")));
            schRepeatID = schRepeatID2 = getIntent().getStringExtra("schRepeatID");
            schID = getIntent().getStringExtra("schID");
            schRemark1 = getIntent().getStringExtra("schRemark1");
            path = getIntent().getStringExtra("schImagePath");
            list.clear();
            list = App.getDBcApplication().getCalenderNoteDetailData(userid, maxTitleId, false);
            mMap = App.getDBcApplication().querayOneCalenderData(Integer.valueOf(schID));
            stylee = mMap.get(ScheduleTable.schSourceDescSpare).equals("") ? 0 : Integer.valueOf(mMap.get(ScheduleTable.schSourceDescSpare));
            showTitleImage(path);
            if (isAlarm == 3) {
                calender_tixing.setText("(两次提醒)");
            } else {
                calender_tixing.setText("(一次提醒)");
            }

            if (schDisplayTime == 0) {
                calender_time.setText("全天");
            } else {
                o_ll.setVisibility(View.VISIBLE);
                calender_time.setText(schTime);
            }
            if (schIsPostpone == 1) {
                shun.setChecked(true);
            } else {
                shun.setChecked(false);
            }
            if (maxTitleId.isEmpty()) {
                maxTitleId = DateUtil.nowTime2();
            }
            if (list.size() > 0) {
                bottom_ll.setVisibility(View.VISIBLE);
            } else {
                bottom_ll.setVisibility(View.GONE);
//                enter(0,"");
//                editTextC.setFocusable(true);
            }
            calender_week.setText(Week(calender_date.getText().toString()));
        } else {
            maxTitleId = DateUtil.nowTime2();
            schTime = DateUtil.formatDateTimeHm(new Date());
            calender_date.setText(Today());
            calender_week.setText(Week(Today()));
            calender_time.setText("全天");
            isAlarm = 0;

            if (suntype.equals("1")) {
                schIsPostpone = 1;
                shun.setChecked(true);
            } else {
                schIsPostpone = 0;
                shun.setChecked(false);
            }

            if (getIntent().getStringExtra("lingshengnames") != null && !getIntent().getStringExtra("lingshengnames").isEmpty()) {
                lingshengnames = getIntent().getStringExtra("lingshengnames");
                lingshengcode = getIntent().getStringExtra("lingshengcode");
                schTime = getIntent().getStringExtra("schTime");
                calender_date.setText(getIntent().getStringExtra("schDate"));
                schDisplayTime = getIntent().getIntExtra("schDisplayTime", 0);
                schIsPostpone = getIntent().getIntExtra("schIsPostpone", 0);
                calender_week.setText(Week(calender_date.getText().toString()));
                if (schDisplayTime == 0) {
                    calender_time.setText("全天");
                } else {
                    o_ll.setVisibility(View.VISIBLE);
                    calender_time.setText(schTime);
                }
                if (schIsPostpone == 1) {
                    shun.setChecked(true);
                } else {
                    shun.setChecked(false);
                }
            }
            Title2 = getIntent().getStringExtra("content");
            if (Title2 != null) {
                editTextC.setText(Title2);
            }
        }

        if (!isNewList) {
            if (Title.isEmpty()) {
                editTextC.setTextSize(18);
                editTextC.setTextAppearance(context, R.style.text_style_normal);
                editTextC.setHintTextColor(getResources().getColor(R.color.gongkai_txt3));
            } else {
                editTextC.setText(Title);
                editTextC.setTextSize(20);
                editTextC.setTextAppearance(context, R.style.text_style_bold);
            }
            if (Title.length() > 30) {
                Title = Title.substring(0, 30);
            }
            editTextC.setSelection(Title.length());
            if (list.size() > 0) {

                sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.ADDQDCOPY, addcopy);
                sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.ADDQDICON, "" + addicon);
            }
        } else {
            maxTitleId = DateUtil.nowTime2();
//            enter(0,"");
//            editTextC.setFocusable(true);
        }


        if (!isNewList) {
            if (list.size() == 0) {
                myschedule_title.setText("编辑");
            } else {
                if (stylee == 0) {
                    int endstate = 0;
                    for (CalenderNoteBean.PageBean.ItemsBean bean : list) {
                        if (bean.endstate == 1) {
                            endstate++;
                        }
                    }
                    myschedule_title.setText("编辑(" + endstate + "/" + list.size() + ")");
                } else if (stylee == 4) {
                    myschedule_title.setText("编辑(" + nums() + ")");
                } else {
                    myschedule_title.setText("编辑(" + list.size() + ")");
                }
            }
        } else {
            myschedule_title.setText("新建日程");
        }
        if (list.size() > 0) {
            bottom_ll.setVisibility(View.VISIBLE);
        } else {
            bottom_ll.setVisibility(View.GONE);
        }

        ILoadingLayout loadingLayout = scrollview.getLoadingLayoutProxy();
        loadingLayout.setPullLabel("");
        loadingLayout.setRefreshingLabel("");
        loadingLayout.setReleaseLabel("");
        loadingLayout.setDrawableVisiable(true);
//        scrollview.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ScrollView>() {
//            @Override
//            public void onRefresh(PullToRefreshBase<ScrollView> refreshView) {
//                remark = "0";
//                App.getDBcApplication().updateNoteIsTitle(maxTitleId, userid, remark);
//                titleEd();
//                scrollview.onRefreshComplete();
//            }
//        });
        scrollview.setRefreshing(false);

        titleEd();
        loadData();
    }

    private void titleEd() {
        if (remark.equals("1")) {
            editTextC.setVisibility(View.GONE);
            isNOTETB = false;
            isTitleOnfouns = false;
            Title = "";
            editTextC.setText(Title);
            setListTitle(Title);
            scrollview.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
//            image_line.setVisibility(View.GONE);
            editTextC.setTextSize(18);
            editTextC.setTextAppearance(context, R.style.text_style_normal);
            editTextC.setHintTextColor(getResources().getColor(R.color.gongkai_txt3));
//            xiala_tishi_tv.setVisibility(View.VISIBLE);
        } else {
//            image_line.setVisibility(View.VISIBLE);
//            if (header_image_flag) {
//                image_line.setVisibility(View.GONE);
//            }
//            xiala_tishi_tv.setVisibility(View.GONE);
            scrollview.setMode(PullToRefreshBase.Mode.DISABLED);
            editTextC.setVisibility(View.VISIBLE);
            editTextC.setEdittextCoutomListener(this);
            editTextC.setFocusable(true);
            editTextC.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    isNOTETB = true;
                    isTitleOnfouns = true;
                    Title = s.toString();
//                    if (s.length() == 30) {
//                        Toast.makeText(context, "标题内容请保持在30个字以内!", Toast.LENGTH_LONG).show();
//                    }
                    if (s.length() > 0) {
                        editTextC.setTextSize(20);
                        editTextC.setTextAppearance(context, R.style.text_style_bold);
                    } else {
                        editTextC.setTextSize(18);
                        editTextC.setTextAppearance(context, R.style.text_style_normal);
                        editTextC.setHintTextColor(getResources().getColor(R.color.gongkai_txt3));
                    }
                    setListTitle(Title);
                    if (!isNewList && !schRepeatID.equals("0") && !Title2.equals(Title)) {
                        isRepeatEidt = true;
                        isCopyChild = false;
                        maxTitleId = DateUtil.nowTime2();
                        copyRepeatChild();
                        schRepeatID = "0";
                    }
                }

                @Override
                public void afterTextChanged(Editable s) {
                }
            });
            editTextC.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    isTitleOnfouns = hasFocus;
                }
            });
        }
    }


    /**
     * 修改所有的标题
     *
     * @param title
     */
    private void setListTitle(String title) {
        App.getDBcApplication().updateCalenderNoteTitle(maxTitleId, userid, title, isNewList);
        for (CalenderNoteBean.PageBean.ItemsBean bean : list) {
            bean.titles = title;
        }
    }


    /**
     * 修改清单列表样式
     */
    public void setstyle() {
        for (CalenderNoteBean.PageBean.ItemsBean bean : list) {
            bean.style = stylee;
        }
        App.getDBcApplication().setCalenderNoteStyle(maxTitleId, userid, stylee, isNewList);
        isNOTETB = true;
        sendHandler(1);
        showStyle();
    }

    private void sendHandler(int what) {
        Message message = new Message();
        message.what = what;
        handler.sendMessage(message);
    }

    public Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 1:
                    if (!isNewList) {
                        if (list.size() == 0) {
                            myschedule_title.setText("编辑");
                        } else {
                            if (stylee == 0) {
                                int endstate = 0;
                                for (CalenderNoteBean.PageBean.ItemsBean bean : list) {
                                    if (bean.endstate == 1) {
                                        endstate++;
                                    }
                                }
                                myschedule_title.setText("编辑(" + endstate + "/" + list.size() + ")");
                            } else if (stylee == 4) {
                                myschedule_title.setText("编辑(" + nums() + ")");
                            } else {
                                myschedule_title.setText("编辑(" + list.size() + ")");
                            }
                        }
                    } else {
                        myschedule_title.setText("新建日程");
                    }
                    if (list.size() > 0) {
                        bottom_ll.setVisibility(View.VISIBLE);
                    } else {
                        bottom_ll.setVisibility(View.GONE);
                    }
                    break;
            }
        }
    };

    private void loadData() {
        if (isNewList) {
//            insertData();
        } else {
            px();
            isNOTETB = false;
        }
    }

    @Override
    protected void setAdapter() {
    }

    boolean istitle1 = false;
    String title1 = "";
    MediaPlayer mediaPlayer = new MediaPlayer();
    AssetFileDescriptor fileDescriptor = null;

    int isLongJTImage = 0;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.top_ll_back:
                onBackPressed();
                break;
            case R.id.my_friend_ll_right:
                CalenderNoteEditRightMenuDialog noteEditRightMenuDialog = new CalenderNoteEditRightMenuDialog(context, R.style.dialog_translucent,
                        getWindowManager(), header_image_flag);
                noteEditRightMenuDialog.show();
                noteEditRightMenuDialog.setCallBack(new CalenderNoteEditRightMenuDialog.CallBack() {

                    @Override
                    public void image(boolean isimage, int type) {
                        isLongJTImage = type;
                        if (header_image_flag) {
                            isDeleteImage = true;
                            upimage("", "");
                        } else {
                            setHeaderImage();
                        }
                    }

                    @Override
                    public void shareweixin() {
                        if (sharedPrefUtil.getString(getApplication(), ShareFile.USERFILE, ShareFile.ISNEWYOUKE, "0").equals("-1")) {
                            isShare = false;
                            upLoadData();
                        } else {
                            Intent newt = new Intent(context, PhoneCodeLoginActivity.class);
                            newt.putExtra("type", 1);
                            newt.putExtra("login", true);
                            startActivity(newt);
                        }
                    }

                    @Override
                    public void savenote() {
                        int id = App.getDBcApplication().getTiMinId() - 1;
                        String newtitleid = DateUtil.nowTime1();
                        NoteTitleDetailBean.TDelListBean bean = new NoteTitleDetailBean.TDelListBean();
                        bean.titleId = newtitleid;
                        bean.uid = Integer.valueOf(userid);
                        bean.id = id;
                        bean.styles = stylee;
                        bean.changeTime = DateUtil.nowTime();
                        bean.createTime = DateUtil.nowTime();
                        bean.localTimes = DateUtil.nowTime();
                        bean.ltype = 0;
                        bean.orderId = 0;
                        bean.copys = "0";
                        bean.filed = "0";
                        bean.titles = editTextC.getText().toString();
                        bean.imgPath = path;
                        bean.imgUrl = "";
                        bean.nums = "";
                        bean.shareUrl = "";
                        bean.remark = "0";
                        bean.remark1 = "0";
                        bean.remark2 = "";
                        bean.remark3 = "";
                        bean.pname = "";
                        bean.puid = 0;
                        bean.states = 0;
                        bean.sends = 0;
                        bean.openState = 0;
                        bean.other1 = "0";

                        App.getDBcApplication().saveNoteTitleData(bean);
                        App.getDBcApplication().updateNoteTitleState(bean.titleId, userid, 1, false);
                        for (int j = 0; j < list.size(); j++) {
                            NoteTitleDetailBean.ListBean listBean = new NoteTitleDetailBean.ListBean();
                            listBean.titleId = newtitleid;
                            listBean.uid = Integer.valueOf(userid);
                            listBean.id = App.getDBcApplication().getMinId() - 1;
                            listBean.style = list.get(j).style;
                            listBean.changetime = DateUtil.nowTime();
                            listBean.createTime = DateUtil.nowTime();
                            listBean.lType = 0;
                            listBean.orderId = j + 1;
                            listBean.endstate = 0;
                            listBean.remark = "";
                            listBean.contents = list.get(j).contents;
                            listBean.titles = editTextC.getText().toString();
                            listBean.imgPath = path;
                            listBean.imgUrl = "";
                            listBean.cpath = "";
                            listBean.curl = "";
                            listBean.nums = "";
                            listBean.shareUrl = "";
                            listBean.remark1 = "";
                            listBean.remark2 = "";
                            listBean.remark3 = "";
                            listBean.remark4 = "";

                            App.getDBcApplication().saveNoteDetailData(listBean);
                            App.getDBcApplication().updateNoteTitleDetailState(newtitleid, listBean.id, userid, 1, false);
                        }
                        Toast.makeText(context, "已保存", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void copyall() {
                        String copallcontent = "**" + editTextC.getText().toString() + "**";
                        for (CalenderNoteBean.PageBean.ItemsBean listBean : list) {
//                            if (stylee == 0) {
//                                copallcontent += "\n\n□ " + listBean.contents;
//                            } else if (stylee == 1) {
//                                copallcontent += "\n\n• " + listBean.contents;
//                            } else if (stylee == 2) {
//                                copallcontent += "\n\n" + listBean.orderId + "." + listBean.contents;
//                            } else if (stylee == 3) {
                            copallcontent += "\n\n" + listBean.contents;
//                            }

                        }
                        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                        cm.setText(copallcontent);
                        Toast.makeText(context, "已复制", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void copyone() {
                        initRiliDiaLog(true, "");
                    }

                    @Override
                    public void share() {
                        if (sharedPrefUtil.getString(getApplication(),
                                ShareFile.USERFILE, ShareFile.ISNEWYOUKE, "0").equals("-1")) {
                            isShare = true;
                            upLoadData();
                        } else {
                            Intent newt = new Intent(context, PhoneCodeLoginActivity.class);
                            newt.putExtra("type", 1);
                            newt.putExtra("login", true);
                            startActivity(newt);
                        }
                    }
                });
                break;
            case R.id.copy:
                copyItem();
                break;
            case R.id.sty:
                alterstyleDialog();
                break;
            case R.id.yl:
                Intent intentyl = new Intent(CalenderNoteEditActivity.this, QDFXDetailActivity.class);
                intentyl.putExtra("title", Title);
                intentyl.putExtra("titleId", maxTitleId);
                intentyl.putExtra("path", path);
                intentyl.putExtra("goodNum", "0");
                intentyl.putExtra("redNum", "1");
                intentyl.putExtra("stylee", stylee);
                intentyl.putExtra("type", 6);//预览
                intentyl.putExtra("name", sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERNAME, ""));
                intentyl.putExtra("time", App.getDBcApplication().getOneNoteTitlesData(userid, maxTitleId, false).createTime);
                intentyl.putExtra("num", App.getDBcApplication().getOneNoteTitlesData(userid, maxTitleId, false).nums);
                intentyl.putExtra("uid", userid);
                startActivityForResult(intentyl, 602);
                break;
            case R.id.px:
                updateList();
                Intent intent = new Intent(context, CalenderNotepxActivity.class);
                Bundle bun = new Bundle();
                bun.putSerializable("list", (Serializable) list);
                intent.putExtras(bun);
                intent.putExtra("stylee", stylee);
                startActivityForResult(intent, 603);
                break;
            case R.id.header_image:
                isLongJTImage = 0;
                setHeaderImage();
                break;
            case R.id.calender_sing:
                CalenderRingDialog calenderRingDialog = new CalenderRingDialog(context,
                        R.style.dialog_translucent, getWindowManager(), "", "");
                calenderRingDialog.setCallBack(new CalenderRingDialog.CallBack() {
                    @Override
                    public void reminderEditTime(String lingshengname, String code) {
                        lingshengnames = lingshengname;
                        lingshengcode = code;
                        calender_sing.setText(lingshengname);
                        try {
                            mediaPlayer.reset();
                            fileDescriptor = getAssets().openFd(lingshengcode + ".mp3");
                            mediaPlayer.setDataSource(
                                    fileDescriptor.getFileDescriptor(),
                                    fileDescriptor.getStartOffset(),
                                    fileDescriptor.getLength());
                            mediaPlayer.prepare();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
                calenderRingDialog.show();
                break;
            case R.id.calender_tixing:
                initBeforeDiaLog(calender_tixing, null);
                break;
            case R.id.date_ll:
                initRiliDiaLog(false, "");
                break;
            case R.id.time_ll:
                if (sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.CLOCKORDER, "0").equals("0")) {
                    dialogMorningTimeOnClick(calender_time);
                } else {
                    initDiaLog(calender_time);
                }
                break;
            default:
                break;
        }
    }

    boolean isShare = false;

    private void deleteEmpty() {
        isNOTETB = true;
        List<CalenderNoteBean.PageBean.ItemsBean> list = App.getDBcApplication().getCalenderNoteDetailData(userid, maxTitleId, false);
        if (list != null) {
            //标题为空,content为空,删除该id
            for (CalenderNoteBean.PageBean.ItemsBean bean : list) {
                if (bean.contents.isEmpty()) {
                    if (bean.id < 0) {
                        App.getDBcApplication().deleteCalenderNoteDetail(bean.id, maxTitleId, userid, true);
                    } else {
                        App.getDBcApplication().deleteCalenderNoteDetail(bean.id, maxTitleId, userid, isNewList);
                    }
                }
            }
        }
    }

    /**
     * 样式
     */
    private void alterstyleDialog() {
        Dialog dialog = new Dialog(context, R.style.dialog_translucent_adjustPan);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(context);
        View more_pop_menu = fac.inflate(R.layout.addqdlist_style_dialog, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = ViewGroup.LayoutParams.MATCH_PARENT;
        dialog.show();

        new alterstyleDialogOnClick(dialog, more_pop_menu);
    }

    //----------------------------------------------------
    int copyi = 0;//1 top,2 bottom

    boolean isEnter = false;//是否在换行

    /**
     * 新增一项
     *
     * @param index
     * @param text
     */
    @Override
    public void enter(int index, String text) {
        isNOTETB = true;
        isEnter = true;
        int newid = App.getDBcApplication().getCalenderMinId() - 1;
        CalenderNoteBean.PageBean.ItemsBean bean = new CalenderNoteBean.PageBean.ItemsBean();
        bean.titleId = maxTitleId;
        bean.uid = Integer.valueOf(userid);
        bean.id = newid;
        bean.style = stylee;
        bean.changeTime = DateUtil.nowTime();
        bean.createTime = DateUtil.nowTime();
        bean.ltype = Integer.valueOf(addicon);
        bean.orderId = addcopy.equals("1") ? 1 : mEditTextList.getChildCount() + 1;
        bean.endstate = 0;
        bean.remark = "";
        bean.contents = text;
        bean.titles = Title;
        bean.imgPath = path;
        bean.imgUrl = "";
        bean.cpath = "";
        bean.curl = "";
        bean.sdesc = "";
        bean.nums = "";
        bean.localIds = DateUtil.nowTime2();
        bean.shareUrl = "";
        bean.remark1 = "";
        bean.remark2 = "";
        bean.remark3 = "";
        bean.remark4 = "";
        bean.remark5 = "";
        bean.remark6 = "";

        if (list.size() > 0) {
            list.add(index, bean);
        } else {
            list.add(bean);
        }
        App.getDBcApplication().saveCalederNoteDetailData(bean);
        App.getDBcApplication().updateCalenderNoteDetailState(maxTitleId, bean.id, userid, 1, isNewList);

        if (index > mEditTextList.getChildCount()) {
            Log.e("TAG", "Error mEditTextList.getChildCount()");
        }
        View view;
        if (isTitleOnfouns) {
            isTitleOnfouns = false;
//            setcolor(Title, editTextC);
            if (editTextC.getText().toString().isEmpty()) {
                editTextC.setText("无标题");
            }

            view = getListItem(0, bean, true);
            mEditTextList.addView(view, 0);
        } else {
            if (copyi != 1) {
                if (index > 0) {
                    EditTextC lastEdit = (EditTextC) mEditTextList.getChildAt(index - 1).findViewById(R.id.et_edit_text);
                    setcolor(lastEdit.getText().toString(), lastEdit);
                }
            }

            view = getListItem(index, bean, true);
            mEditTextList.addView(view, index);
        }


        EditTextC edit = (EditTextC) view.findViewById(R.id.et_edit_text);
        edit.requestFocus();
        edit.setSelection(0);
        for (int i = 0; i < mEditTextList.getChildCount(); i++) {
            ((EditTextC) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text)).setIndex(i);
            ((TextView) mEditTextList.getChildAt(i).findViewById(R.id.xh)).setText((i + 1) + ". ");
            ((CheckBoxC) mEditTextList.getChildAt(i).findViewById(R.id.ch)).setIndex(i);
            ((TextViewC) mEditTextList.getChildAt(i).findViewById(R.id.tv_gd)).setIndex(i);
            ((TextViewC) mEditTextList.getChildAt(i).findViewById(R.id.tv_delete)).setIndex(i);
            ((CButton) mEditTextList.getChildAt(i).findViewById(R.id.santai_button)).setIndex(i);
            App.getDBcApplication().updateNoteDetailOrderId(i + 1, list.get(i).id, maxTitleId, userid, isNewList);
            App.getDBcApplication().updateCalenderNoteDetailEndstate(list.get(i).id, list.get(i).endstate, maxTitleId, userid, isNewList);
        }
        copyi = 0;
        sendHandler(1);

        isEnter = false;
    }

    boolean isTitleOnfouns = false;

    /**
     * 删除一项
     *
     * @param index
     * @param text
     */
    @Override
    public void delete(int index, String text) {
        isNOTETB = true;
//        if (isTitleOnfouns == false) {

        //只有一项的时候不能删除
        if (mEditTextList.getChildCount() > 0) {

            App.getDBcApplication().deleteNoteDetail(list.get(index).id, maxTitleId, userid, isNewList);
            list.remove(index);
            mEditTextList.removeViewAt(index);

            for (int i = 0; i < mEditTextList.getChildCount(); i++) {
                ((EditTextC) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text)).setIndex(i);
                ((TextView) mEditTextList.getChildAt(i).findViewById(R.id.xh)).setText((i + 1) + ". ");
                ((CheckBoxC) mEditTextList.getChildAt(i).findViewById(R.id.ch)).setIndex(i);
                ((TextViewC) mEditTextList.getChildAt(i).findViewById(R.id.tv_gd)).setIndex(i);
                ((TextViewC) mEditTextList.getChildAt(i).findViewById(R.id.tv_delete)).setIndex(i);
                ((CButton) mEditTextList.getChildAt(i).findViewById(R.id.santai_button)).setIndex(i);
                App.getDBcApplication().updateNoteDetailOrderId(i + 1, list.get(i).id, maxTitleId, userid, isNewList);
                App.getDBcApplication().updateCalenderNoteDetailEndstate(list.get(i).id, list.get(i).endstate, maxTitleId, userid, isNewList);
            }

            EditTextC edit;
            if (index == 0) {
                if (mEditTextList.getChildCount() > 0) {
                    if (index == 0) {
                        onFouns = 0;
                        edit = (EditTextC) mEditTextList.getChildAt(0).findViewById(R.id.et_edit_text);
                        edit.append(text, 0, 0);
                        edit.requestFocus();
                        edit.setSelection(edit.length());
                    } else {
                        editTextC.append(text);
                        editTextC.requestFocus();
                        editTextC.setSelection(editTextC.getText().length());
                    }
                } else {
                    if (!maxTitleId.equals("0")) {
                        editTextC.append(text);
                        editTextC.requestFocus();
                        editTextC.setSelection(editTextC.getText().length());
                    }
                }
            } else {
                onFouns = index - 1;
                edit = (EditTextC) mEditTextList.getChildAt(index - 1).findViewById(R.id.et_edit_text);
                edit.append(text);
                edit.requestFocus();
                edit.setSelection(edit.length());
            }

        }
//        }

        sendHandler(1);
    }

    @Override
    public void textchange(int index, boolean hastext) {
//        if (mEditTextList.getChildCount() > 0) {
//            for (int i = 0; i < mEditTextList.getChildCount(); i++) {
//                if (mEditTextList.getChildCount() == 1) {
//                    ((EditTextC) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text)).setHint("请输入内容");
//                } else {
//                    ((EditTextC) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text)).setHint("");
//                }
//            }
//        }
    }

    private boolean isPX = false;

    private void px() {
        isChildEdit = false;
        isPX = true;
        if (list.size() > 0) {
            mEditTextList.removeAllViews();
            for (int i = 0; i < list.size(); i++) {
                //赋予当前id的序列号值
                App.getDBcApplication().updateCalenderNoteDetailOrderId(i + 1, list.get(i).id, maxTitleId, userid, isNewList);
                View view = getListItem(i, list.get(i), false);
                mEditTextList.addView(view, i);
            }
        }
        editTextC.clearFocus();
        isChildEdit = true;
        isPX = false;
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                scrollview.scrollTo(0, 0);
            }
        });
    }

    boolean isCopyBottomMenu = false;

    /**
     * 粘贴一条清单项
     */
    private void copyItem() {
        ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        if (clipboardManager.getText() == null || clipboardManager.getText().toString().isEmpty()) {
            alertClipIsEmptry();
        } else {
            isNOTETB = true;
            isCopyBottomMenu = true;
//            if (sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.ADDFENDUAN, "0").equals("0")) {
            String[] items = clipboardManager.getText().toString().split("\n");
            for (String item : items) {

                if (!item.isEmpty()) {
                    if (editTextC.hasFocus()) {
                        editTextC.setText(item);
                    } else {
                        if (addcopy.equals("1")) {
                            copyi = 2;
                            if (mEditTextList.getChildCount() == 1) {
                                EditTextC editTextC = (EditTextC) mEditTextList.getChildAt(0).findViewById(R.id.et_edit_text);
                                String s = editTextC.getText().toString();
                                if (s.isEmpty()) {
                                    editTextC.setText(item);
                                    editTextC.setSelection(item.length());
                                } else {
                                    enter(mEditTextList.getChildCount(), item);
                                }
                            } else {
                                enter(mEditTextList.getChildCount(), item);
                            }
                        } else {
                            copyi = 1;
                            if (mEditTextList.getChildCount() == 1) {
                                EditTextC editTextC = (EditTextC) mEditTextList.getChildAt(0).findViewById(R.id.et_edit_text);
                                String s = editTextC.getText().toString();
                                if (s.isEmpty()) {
                                    editTextC.setText(item);
                                    editTextC.setSelection(item.length());
                                } else {
                                    enter(0, item);
                                }
                            } else {
                                enter(0, item);
                            }
                        }
                    }
                }
            }
//            } else {
//                if (editTextC.hasFocus()) {
//                    editTextC.setText(clipboardManager.getText().toString());
//                } else {
//                    if (addcopy.equals("1")) {
//                        copyi = 2;
//                        if (mEditTextList.getChildCount() == 1) {
//                            EditTextC editTextC = (EditTextC) mEditTextList.getChildAt(0).findViewById(R.id.et_edit_text);
//                            String s = editTextC.getText().toString();
//                            if (s.isEmpty()) {
//                                editTextC.setText(clipboardManager.getText().toString());
//                                editTextC.setSelection(clipboardManager.getText().toString().length());
//                            } else {
//                                enter(mEditTextList.getChildCount(), clipboardManager.getText().toString());
//                            }
//                        } else {
//                            enter(mEditTextList.getChildCount(), clipboardManager.getText().toString());
//                        }
//                    } else {
//                        copyi = 1;
//                        if (mEditTextList.getChildCount() == 1) {
//                            EditTextC editTextC = (EditTextC) mEditTextList.getChildAt(0).findViewById(R.id.et_edit_text);
//                            String s = editTextC.getText().toString();
//                            if (s.isEmpty()) {
//                                editTextC.setText(clipboardManager.getText().toString());
//                                editTextC.setSelection(clipboardManager.getText().toString().length());
//                            } else {
//                                enter(0, clipboardManager.getText().toString());
//                            }
//                        } else {
//                            enter(0, clipboardManager.getText().toString());
//                        }
//                    }
//                }
//            }

        }
        isCopyBottomMenu = false;
    }

    private void alertClipIsEmptry() {
        final AlertDialog builder = new AlertDialog.Builder(context).create();
        builder.show();
        Window window = builder.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        params.alpha = 0.92f;
        params.gravity = Gravity.CENTER;
        window.setAttributes(params);// 设置生效
        window.setGravity(Gravity.CENTER);
        window.setContentView(R.layout.dialog_alert_ok);
        TextView delete_ok = (TextView) window.findViewById(R.id.delete_ok);
        TextView delete_tv = (TextView) window.findViewById(R.id.delete_tv);
        delete_tv.setText("粘贴内容不能为空！");
        delete_ok.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                builder.cancel();
            }
        });
    }

    List<SwipeLinearLayout> swipeLinearLayouts = new ArrayList<>();

    private View getListItem(int index, final CalenderNoteBean.PageBean.ItemsBean bean, boolean isEdit) {
        final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        View view = LayoutInflater.from(this).inflate(R.layout.note_edit_list_item, null);
        final EditTextC edit = (EditTextC) view.findViewById(R.id.et_edit_text);
        final CButton santai_button = (CButton) view.findViewById(R.id.santai_button);
        final SwipeLinearLayout swipeLayout = (SwipeLinearLayout) view.findViewById(R.id.swipelayout);
//        SwipeLayout.addSwipeView(swipeLayout);
        swipeLinearLayouts.add(swipeLayout);
        swipeLayout.setOnSwipeListener(new SwipeLinearLayout.OnSwipeListener() {
            @Override
            public void onDirectionJudged(SwipeLinearLayout thisSll, boolean isHorizontal) {
                if (false == isHorizontal) {
                    for (SwipeLinearLayout sll : swipeLinearLayouts) {
                        if (null == sll) {
                            continue;
                        }
                        sll.scrollAuto(SwipeLinearLayout.DIRECTION_SHRINK);
                    }
                } else {
                    for (SwipeLinearLayout sll : swipeLinearLayouts) {
                        if (null == sll) {
                            continue;
                        }
                        if (!sll.equals(thisSll)) {
                            //划开一个sll， 其他收缩
                            sll.scrollAuto(SwipeLinearLayout.DIRECTION_SHRINK);
                        }
                    }
                }
            }
        });

        final TextViewC more = (TextViewC) view.findViewById(R.id.tv_gd);
        more.setIndex(index);
        more.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                swipeLayout.scrollAuto(SwipeLinearLayout.DIRECTION_SHRINK);
                moreindex = more.getIndex();
                copymessage = ((EditTextC) mEditTextList.getChildAt(more.getIndex()).findViewById(R.id.et_edit_text)).getText().toString();
//                alterMoreDialog();
                CalenderNoteEditChildMenuDialog noteEditChildMenuDialog = new CalenderNoteEditChildMenuDialog(context, R.style.dialog_translucent,
                        getWindowManager());
                noteEditChildMenuDialog.show();
                noteEditChildMenuDialog.setCallBack(new CalenderNoteEditChildMenuDialog.CallBack() {
                    @Override
                    public void copycontent() {
                        // 为了兼容低版本我们这里使用旧版的android.text.ClipboardManager，虽然提示deprecated，但不影响使用。
                        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                        // 将文本内容放到系统剪贴板里。
                        cm.setText(copymessage);
                        Toast.makeText(context, "已复制", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void copy() {
                        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                        // 将文本内容放到系统剪贴板里。
                        cm.setText(copymessage);
                        copyItem();
                    }

                    @Override
                    public void settitle() {
                        remark = "0";
                        App.getDBcApplication().updateNoteIsTitle(maxTitleId, userid, remark);
                        editTextC.setText(copymessage);
                        titleEd();
                    }

                    @Override
                    public void adddaiban() {
                        if (!"".equals(copymessage.trim())) {
                            try {
                                App.getDBcApplication().insertScheduleData(copymessage, DateUtil.formatDate(new Date()),
                                        DateUtil.formatDateTimeHm(new Date()), 1,
                                        0, 0, 1, 0,
                                        0, 0, DateUtil.formatDateTime(new Date()), "", 0,
                                        "", "", 0, "", DateUtil.formatDateTime(new Date()),
                                        1, 0, 0, "完成任务", "g_88", "", 0, 0, 0, "",
                                        "", 0, 0, 0, 0, schRemark1, "0", "0");
                                QueryAlarmData.writeAlarm(context.getApplicationContext());
                                Intent intentappwidget = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                                Bundle extras = new Bundle();
                                intentappwidget.putExtras(extras);
                                sendBroadcast(intentappwidget);
                                Intent intent1 = new Intent(Const.SHUAXINDATA);
                                intent1.putExtra("data", "success");
                                intent1.putExtra("index", 1);
                                intent1.putExtra("what", 2);
                                context.sendBroadcast(intent1);

                                Toast.makeText(context, "添加成功", Toast.LENGTH_SHORT).show();
                            } catch (NumberFormatException e) {
                                e.printStackTrace();
                            }
                        } else {
                            Toast.makeText(context, "内容不能为空", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    public void add_calender() {
                        initRiliDiaLog(true, copymessage);
                    }
                });
            }
        });

        final TextViewC delete = (TextViewC) view.findViewById(R.id.tv_delete);
        delete.setIndex(index);
        delete.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                swipeLayout.scrollAuto(SwipeLinearLayout.DIRECTION_SHRINK);
                if (mEditTextList.getChildCount() > 1) {
                    App.getDBcApplication().deleteCalenderNoteDetail(list.get(delete.getIndex()).id, maxTitleId, userid, isNewList);
                    list.remove(delete.getIndex());
                    mEditTextList.removeViewAt(delete.getIndex());

                    int childcount = mEditTextList.getChildCount();
                    if (childcount > 0) {
                        for (int i = 0; i < mEditTextList.getChildCount(); i++) {
                            ((EditTextC) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text)).setIndex(i);
                            ((TextView) mEditTextList.getChildAt(i).findViewById(R.id.xh)).setText((i + 1) + ". ");
                            ((CheckBoxC) mEditTextList.getChildAt(i).findViewById(R.id.ch)).setIndex(i);
                            ((TextViewC) mEditTextList.getChildAt(i).findViewById(R.id.tv_gd)).setIndex(i);
                            ((TextViewC) mEditTextList.getChildAt(i).findViewById(R.id.tv_delete)).setIndex(i);
                            ((CButton) mEditTextList.getChildAt(i).findViewById(R.id.santai_button)).setIndex(i);
                            App.getDBcApplication().updateCalenderNoteDetailEndstate(list.get(i).id, list.get(i).endstate, maxTitleId, userid, isNewList);
                            App.getDBcApplication().updateCalenderNoteDetailOrderId(i + 1, list.get(i).id, maxTitleId, userid, isNewList);
                        }
                    }
                    imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
                } else {
                    ((EditTextC) mEditTextList.getChildAt(0).findViewById(R.id.et_edit_text)).setText("");
                    list.get(onFouns).contents = "";
                    list.get(onFouns).changeTime = DateUtil.nowTime();
                    //修改修改时间
                    App.getDBcApplication().updateCalenderNoteDetail(list.get(onFouns).id, maxTitleId, userid, "", list.get(onFouns).changeTime, isNewList);

                }
            }
        });


        edit.setEdittextCoutomListener(this);
        final CheckBoxC cb = (CheckBoxC) view.findViewById(R.id.ch);
        TextView xh = (TextView) view.findViewById(R.id.xh);
        ImageView yd = (ImageView) view.findViewById(R.id.yd);
        RelativeLayout left_rl = (RelativeLayout) view.findViewById(R.id.left_rl);
        final View edit_line = view.findViewById(R.id.edit_line);
        View em = view.findViewById(R.id.em);
        left_rl.setVisibility(View.VISIBLE);
        em.setVisibility(View.GONE);

        if (stylee == 0) {
            cb.setVisibility(View.VISIBLE);
            xh.setVisibility(View.GONE);
            yd.setVisibility(View.GONE);
            santai_button.setVisibility(View.GONE);
        } else if (stylee == 1) {
            cb.setVisibility(View.GONE);
            xh.setVisibility(View.GONE);
            yd.setVisibility(View.VISIBLE);
            santai_button.setVisibility(View.GONE);
        } else if (stylee == 2) {
            cb.setVisibility(View.GONE);
            xh.setVisibility(View.VISIBLE);
            yd.setVisibility(View.GONE);
            santai_button.setVisibility(View.GONE);
        } else if (stylee == 4) {
            cb.setVisibility(View.GONE);
            xh.setVisibility(View.GONE);
            yd.setVisibility(View.GONE);
            santai_button.setVisibility(View.VISIBLE);
        } else if (stylee == 3) {
            em.setVisibility(View.VISIBLE);
            left_rl.setVisibility(View.GONE);
        }
        if (bean.endstate == 0) {
            santai_button.setBackground(getResources().getDrawable(R.drawable.icon_santai1));
        } else if (bean.endstate == 1) {
            santai_button.setBackground(getResources().getDrawable(R.drawable.icon_santai2));
        } else {
            santai_button.setBackground(getResources().getDrawable(R.drawable.icon_santai3));
        }
        santai_button.setIndex(index);
        santai_button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (bean.endstate == 0) {
                    santai_button.setBackground(getResources().getDrawable(R.drawable.icon_santai2));
                    setTick(santai_button.getId(), 1);
                } else if (bean.endstate == 1) {
                    santai_button.setBackground(getResources().getDrawable(R.drawable.icon_santai3));
                    setTick(santai_button.getId(), 2);
                } else {
                    santai_button.setBackground(getResources().getDrawable(R.drawable.icon_santai1));
                    setTick(santai_button.getId(), 0);
                }
            }
        });
        left_rl.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (cb.getVisibility() == View.VISIBLE) {
                    setTick(cb.getIndex(), cb.isChecked() ? 1 : 0);
                } else {
                    if (bean.endstate == 0) {
                        santai_button.setBackground(getResources().getDrawable(R.drawable.icon_santai2));
                        setTick(santai_button.getIndex(), 1);
                    } else if (bean.endstate == 1) {
                        santai_button.setBackground(getResources().getDrawable(R.drawable.icon_santai3));
                        setTick(santai_button.getIndex(), 2);
                    } else {
                        santai_button.setBackground(getResources().getDrawable(R.drawable.icon_santai1));
                        setTick(santai_button.getIndex(), 0);
                    }
                }
            }
        });
        cb.setIndex(index);
        cb.setChecked(bean.endstate == 0 ? false : true);
        cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                setTick(cb.getIndex(), b ? 1 : 0);
            }
        });

        xh.setText((index + 1) + ". ");
        if (!isEdit) {
            edit.clearFocus();
        }
        edit.addTextChangedListener(new NewTextWatcher());
        edit.setIndex(index);

        edit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
//                if (hasFocus) {
                if (!isCopyBottomMenu) {
                    imm.showSoftInput(edit, 0);
//                        edit.setPadding(0, 0, 0, 30);
                } else {
                    imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
//                        edit.setPadding(0, 0, 0, 0);
                }
                isTitleOnfouns = false;
                onFouns = edit.getIndex();
//                    edit_line.setVisibility(View.GONE);
//                } else {
//                    edit.setPadding(0, 0, 0, 0);
//                    edit_line.setVisibility(View.VISIBLE);
//                }
            }
        });

        //赋予当前id的序列号值
        App.getDBcApplication().updateCalenderNoteDetailOrderId(index + 1, bean.id, maxTitleId, userid, isNewList);

        edit.setText(bean.contents);
        if (!istitle1) {
            title1 = bean.contents;
            if (!title1.isEmpty()) {
                istitle1 = true;
            }
        }

        setcolor(bean.contents, edit);
        edit.setSelection(edit.length());
        edit.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Rect r = new Rect();
                getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
                int screenHeight = getWindow().getDecorView().getRootView().getHeight();
                int heightD = screenHeight - r.bottom;
                int l = 144;
                if (screenHeight == 2880) {
                    l = 168;
                }
                if (heightD > l) {
                    bottom_ll.setVisibility(View.GONE);
                } else {
                    bottom_ll.setVisibility(View.VISIBLE);
                }
            }
        });
        return view;
    }

    int onFouns = 0;//焦点位置
    boolean isChildEdit = false;//是否在排序

    class NewTextWatcher implements TextWatcher {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            //重复子记事
            if (!isNewList && !schRepeatID.equals("0") && isCopyChild && !isRepeatEidt && !isPX) {
                isRepeatEidt = true;
                isCopyChild = false;
                maxTitleId = DateUtil.nowTime2();
                copyRepeatChild();
                schRepeatID = "0";
            }
            if (!isEnter) {
                if (isChildEdit) {
                    isNOTETB = true;

                    list.get(onFouns).contents = s.toString();
                    list.get(onFouns).changeTime = DateUtil.nowTime();
                    //修改修改时间
                    App.getDBcApplication().updateCalenderNoteDetail(list.get(onFouns).id, maxTitleId, userid, s.toString(), list.get(onFouns).changeTime, isNewList);

                }
            }
        }

        @Override
        public void afterTextChanged(Editable s) {


            if (!isEnter) {
                if (isChildEdit) {
                    isNOTETB = true;
                    list.get(onFouns).contents = s.toString();
                    list.get(onFouns).changeTime = DateUtil.nowTime();
                    //修改修改时间
                    App.getDBcApplication().updateCalenderNoteDetail(list.get(onFouns).id, maxTitleId, userid, s.toString(), list.get(onFouns).changeTime, isNewList);
                }
            }
        }
    }

    /**
     * 更改样式
     */
    private void showStyle() {
        if (mEditTextList.getChildCount() > 0) {
            for (int i = 0; i < mEditTextList.getChildCount(); i++) {
                mEditTextList.getChildAt(i).findViewById(R.id.em).setVisibility(View.GONE);
                mEditTextList.getChildAt(i).findViewById(R.id.left_rl).setVisibility(View.VISIBLE);
                if (stylee == 1) {
                    mEditTextList.getChildAt(i).findViewById(R.id.yd).setVisibility(View.VISIBLE);
                    mEditTextList.getChildAt(i).findViewById(R.id.ch).setVisibility(View.GONE);
                    mEditTextList.getChildAt(i).findViewById(R.id.xh).setVisibility(View.GONE);
                    mEditTextList.getChildAt(i).findViewById(R.id.santai_button).setVisibility(View.GONE);
                } else if (stylee == 0) {
                    mEditTextList.getChildAt(i).findViewById(R.id.yd).setVisibility(View.GONE);
                    mEditTextList.getChildAt(i).findViewById(R.id.ch).setVisibility(View.VISIBLE);
                    mEditTextList.getChildAt(i).findViewById(R.id.xh).setVisibility(View.GONE);
                    mEditTextList.getChildAt(i).findViewById(R.id.santai_button).setVisibility(View.GONE);
                } else if (stylee == 2) {
                    mEditTextList.getChildAt(i).findViewById(R.id.yd).setVisibility(View.GONE);
                    mEditTextList.getChildAt(i).findViewById(R.id.ch).setVisibility(View.GONE);
                    mEditTextList.getChildAt(i).findViewById(R.id.xh).setVisibility(View.VISIBLE);
                    mEditTextList.getChildAt(i).findViewById(R.id.santai_button).setVisibility(View.GONE);
                } else if (stylee == 4) {
                    mEditTextList.getChildAt(i).findViewById(R.id.yd).setVisibility(View.GONE);
                    mEditTextList.getChildAt(i).findViewById(R.id.ch).setVisibility(View.GONE);
                    mEditTextList.getChildAt(i).findViewById(R.id.xh).setVisibility(View.GONE);
                    mEditTextList.getChildAt(i).findViewById(R.id.santai_button).setVisibility(View.VISIBLE);
                } else if (stylee == 3) {
                    mEditTextList.getChildAt(i).findViewById(R.id.left_rl).setVisibility(View.GONE);
                    mEditTextList.getChildAt(i).findViewById(R.id.em).setVisibility(View.VISIBLE);
                }

            }
        }
        editTextC.clearFocus();
    }


    /**
     * 清单结束  0 未 1 已
     *
     * @param position
     * @param tick
     */
    private void setTick(int position, int tick) {
        isNOTETB = true;
        list.get(position).endstate = tick;
        App.getDBcApplication().updateCalenderNoteDetailEndstate(list.get(position).id, tick, maxTitleId, userid, isNewList);
        if (stylee == 0 || stylee == 4) {
            sendHandler(1);
        }
    }


    //设置双#号包裹的文字颜色
    private void setcolor(String content, TextView textview) {
        if (content.length() > 1) {
            SpannableStringBuilder builder = new SpannableStringBuilder(content);
            List<Integer> integerList = new ArrayList<>();
            int index = 0;
            int count = hit(content, "#");
            if (count > 1) {
                if (count % 2 == 0) {
                    for (int i = 0; i < count; i++) {
                        if (i == 0) {
                            index = content.indexOf("#");
                        } else {
                            index = content.indexOf("#", index + 1);
                        }
                        integerList.add(index);
                    }
                    for (int i = 0; i < integerList.size(); i++) {
                        if (i > 0) {
                            if (i % 2 != 0) {
                                ForegroundColorSpan span = new ForegroundColorSpan(Color.parseColor("#df7926"));
                                builder.setSpan(span, integerList.get(i - 1), integerList.get(i) + 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
                            }
                        }
                    }
                    textview.setText(builder);
                } else {
                    for (int i = 0; i < count - 1; i++) {
                        if (i == 0) {
                            index = content.indexOf("#");
                        } else {
                            index = content.indexOf("#", index + 1);
                        }
                        integerList.add(index);

                    }
                    for (int i = 0; i < integerList.size(); i++) {
                        if (i > 0) {
                            if (i % 2 != 0) {
                                ForegroundColorSpan span = new ForegroundColorSpan(Color.RED);
                                builder.setSpan(span, integerList.get(i - 1), integerList.get(i) + 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
                            }
                        }
                    }
                    textview.setText(builder);
                }
            } else {
                textview.setText(content);
            }
        } else {
            textview.setText(content);
        }
        textview.setLineSpacing(20, 1.0f);
    }

    /**
     * @param a 被匹配的长字符串
     * @param b 匹配的短字符串
     * @return 匹配次数
     */
    public int hit(String a, String b) {
        if (a.length() < b.length()) {
            return 0;
        }
        char[] a_t = a.toCharArray();
        int count = 0;

        for (int i = 0; i < a.length(); i++) {
            StringBuffer buffer = new StringBuffer();
            for (int j = 0; j < b.length(); j++) {
                buffer.append(a_t[i + j]);
            }
            if (buffer.toString().equals(b)) {
                count++;
            }
        }

        return count;
    }


//-----------------------------------------------

    class alterstyleDialogOnClick implements OnClickListener {

        private View view;
        private Dialog dialog;
        private TextView hd_tv, xl_tv, yd_tv, canel_tv, wu_tv, st_tv;
        private LinearLayout hd_l, xl_l, yd_l, wu_l, st_l;

        @SuppressLint("NewApi")
        public alterstyleDialogOnClick(Dialog dialog, View view) {
            this.dialog = dialog;
            this.view = view;
            initview();
        }

        private void initview() {
            canel_tv = (TextView) view.findViewById(R.id.canel_tv);
            canel_tv.setOnClickListener(this);
            hd_tv = (TextView) view.findViewById(R.id.hd_tv);
            xl_tv = (TextView) view.findViewById(R.id.xl_tv);
            yd_tv = (TextView) view.findViewById(R.id.yd_tv);
            st_tv = (TextView) view.findViewById(R.id.st_tv);
            wu_tv = (TextView) view.findViewById(R.id.wu_tv);

            wu_l = (LinearLayout) view.findViewById(R.id.wu_l);
            st_l = (LinearLayout) view.findViewById(R.id.st_l);
            hd_l = (LinearLayout) view.findViewById(R.id.hd_l);
            xl_l = (LinearLayout) view.findViewById(R.id.xl_l);
            yd_l = (LinearLayout) view.findViewById(R.id.yd_l);
            hd_l.setOnClickListener(this);
            xl_l.setOnClickListener(this);
            yd_l.setOnClickListener(this);
            wu_l.setOnClickListener(this);
            st_l.setOnClickListener(this);
            if (stylee == 0) {
                hd_tv.setTextColor(Color.parseColor("#aaaaaa"));
            } else if (stylee == 1) {
                yd_tv.setTextColor(Color.parseColor("#aaaaaa"));
            } else if (stylee == 2) {
                xl_tv.setTextColor(Color.parseColor("#aaaaaa"));
            } else if (stylee == 4) {
                st_tv.setTextColor(Color.parseColor("#aaaaaa"));
            } else {
                wu_tv.setTextColor(Color.parseColor("#aaaaaa"));
            }
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.yd_l:
                    stylee = 1;
                    setstyle();
                    dialog.dismiss();
                    break;
                case R.id.hd_l:
                    stylee = 0;
                    setstyle();
                    dialog.dismiss();
                    break;
                case R.id.xl_l:
                    stylee = 2;
                    setstyle();
                    dialog.dismiss();
                    break;
                case R.id.st_l:
                    stylee = 4;
                    setstyle();
                    dialog.dismiss();
                    break;
                case R.id.wu_l:
                    stylee = 3;
                    setstyle();
                    dialog.dismiss();
                    break;
                case R.id.canel_tv:
                    dialog.dismiss();
                    break;
            }
        }
    }

    boolean header_image_flag = false;

    String copymessage = "";
    int moreindex = 0;

    class alterMoreDialogOnClick implements OnClickListener {

        private View view;
        private Dialog dialog;
        private TextView copy, db, tx, yd_note, copy_note, delete, canel_tv;

        @SuppressLint("NewApi")
        public alterMoreDialogOnClick(Dialog dialog, View view) {
            this.dialog = dialog;
            this.view = view;
            initview();
        }

        private void initview() {
            copy = (TextView) view.findViewById(R.id.copy);
            copy.setOnClickListener(this);
            db = (TextView) view.findViewById(R.id.db);
            db.setOnClickListener(this);
            tx = (TextView) view.findViewById(R.id.tx);
            tx.setOnClickListener(this);
            yd_note = (TextView) view.findViewById(R.id.yd_note);
            yd_note.setOnClickListener(this);
            copy_note = (TextView) view.findViewById(R.id.copy_note);
            copy_note.setOnClickListener(this);
            delete = (TextView) view.findViewById(R.id.delete);
            delete.setOnClickListener(this);
            canel_tv = (TextView) view.findViewById(R.id.canel_tv);
            canel_tv.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.copy:
                    // 为了兼容低版本我们这里使用旧版的android.text.ClipboardManager，虽然提示deprecated，但不影响使用。
                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                    // 将文本内容放到系统剪贴板里。
                    cm.setText(copymessage);
                    Toast.makeText(context, "已复制", Toast.LENGTH_SHORT).show();
                    dialog.dismiss();
                    break;
                case R.id.db:
                    if (!"".equals(copymessage.trim())) {
                        displaytime = 0;
                        postpone = 1;
                        sendMessageDialog(copymessage);
                    } else {
                        Toast.makeText(context, "待办内容不能为空", Toast.LENGTH_SHORT).show();
                    }
                    dialog.dismiss();
                    break;
                case R.id.yd_note:
                    if (!"".equals(copymessage.trim())) {
                        Intent intenty = new Intent(CalenderNoteEditActivity.this, NoteListActivity.class);
                        intenty.putExtra("content", copymessage);
                        intenty.putExtra("maxTitleId", maxTitleId);
                        startActivityForResult(intenty, 605);
                    } else {
                        Toast.makeText(context, "内容不能为空", Toast.LENGTH_SHORT).show();
                    }
                    dialog.dismiss();
                    break;
                case R.id.tx:
                    if (!"".equals(copymessage.trim())) {

                        try {
                            App.getDBcApplication().insertScheduleData(copymessage, DateUtil.formatDate(new Date()),
                                    DateUtil.formatDateTimeHm(new Date()), 1,
                                    0, 1, 0, 0,
                                    0, 0, DateUtil.formatDateTime(new Date()), "", 0,
                                    "", "", 0, "", DateUtil.formatDateTime(new Date()),
                                    1, 0, 0, "完成任务", "g_88", "", 0, 0, 0, "",
                                    "", 0, 0, 0, 0, schRemark1, "0", "0");
                            QueryAlarmData.writeAlarm(context.getApplicationContext());
                            Intent intentappwidget = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                            Bundle extras = new Bundle();
                            intentappwidget.putExtras(extras);
                            sendBroadcast(intentappwidget);
                            Intent intent1 = new Intent(Const.SHUAXINDATA);
                            intent1.putExtra("data", "success");
                            intent1.putExtra("index", 1);
                            intent1.putExtra("what", 2);
                            context.sendBroadcast(intent1);

                            Toast.makeText(context, "添加成功", Toast.LENGTH_SHORT).show();
                        } catch (NumberFormatException e) {
                            e.printStackTrace();
                        }
                    } else {
                        Toast.makeText(context, "内容不能为空", Toast.LENGTH_SHORT).show();
                    }
                    dialog.dismiss();
                    break;
                case R.id.copy_note:
                    if (!"".equals(copymessage.trim())) {
                        Intent intentc = new Intent(CalenderNoteEditActivity.this, NoteListActivity.class);
                        intentc.putExtra("content", copymessage);
                        intentc.putExtra("maxTitleId", maxTitleId);
                        startActivityForResult(intentc, 604);
                    } else {
                        Toast.makeText(context, "内容不能为空", Toast.LENGTH_SHORT).show();
                    }
                    dialog.dismiss();
                    break;
                case R.id.delete:

                    if (mEditTextList.getChildCount() > 1) {
                        App.getDBcApplication().deleteCalenderNoteDetail(list.get(moreindex).id, maxTitleId, userid, isNewList);

                        list.remove(moreindex);
                        mEditTextList.removeViewAt(moreindex);


                        int childcount = mEditTextList.getChildCount();
                        if (childcount > 0) {
                            for (int i = 0; i < mEditTextList.getChildCount(); i++) {
                                ((EditTextC) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text)).setIndex(i);
                                ((TextView) mEditTextList.getChildAt(i).findViewById(R.id.xh)).setText((i + 1) + ". ");
                                ((CheckBoxC) mEditTextList.getChildAt(i).findViewById(R.id.ch)).setIndex(i);
                                ((TextViewC) mEditTextList.getChildAt(i).findViewById(R.id.tv_gd)).setIndex(i);
                                ((TextViewC) mEditTextList.getChildAt(i).findViewById(R.id.tv_delete)).setIndex(i);
                                ((CButton) mEditTextList.getChildAt(i).findViewById(R.id.santai_button)).setIndex(i);
                                App.getDBcApplication().updateNoteDetailOrderId(i + 1, list.get(i).id, maxTitleId, userid, isNewList);
                                App.getDBcApplication().updateCalenderNoteDetailEndstate(list.get(i).id, list.get(i).endstate, maxTitleId, userid, isNewList);
                            }
                        }
                    } else {
                        ((EditTextC) mEditTextList.getChildAt(0).findViewById(R.id.et_edit_text)).setText("");
                        list.get(onFouns).contents = "";
                        list.get(onFouns).changeTime = DateUtil.nowTime();
                        //修改修改时间
                        App.getDBcApplication().updateCalenderNoteDetail(list.get(onFouns).id, maxTitleId, userid, "", list.get(onFouns).changeTime, isNewList);

                    }

                    dialog.dismiss();
                    break;
                case R.id.canel_tv:

                    dialog.dismiss();
                    break;
            }
        }
    }

    final MediaScannerConnection msc = new MediaScannerConnection(mContext, new MediaScannerConnection.MediaScannerConnectionClient() {

        public void onMediaScannerConnected() {
            msc.scanFile("/sdcard/image.jpg", "image/jpeg");
        }

        public void onScanCompleted(String path, Uri uri) {
            msc.disconnect();
        }
    });


    public void setHeaderImage() {
        checkPhonePermission();
        if (autoFag) {
            Crop.pickImage(CalenderNoteEditActivity.this);
        } else {
            Toast.makeText(context, "权限已禁止访问!", Toast.LENGTH_LONG).show();
        }
    }

    private ProgressUtil progressUtil = new ProgressUtil();

    /**
     * 上传清单标题图片
     *
     * @param imagePath
     * @param imageName
     */

    //是否是删除图片
    boolean isDeleteImage = false;

    private void upimage(String imagePath, String imageName) {
        if (NetUtil.getConnectState(this) == NetWorkState.NONE) {
            Toast.makeText(context, "网络异常，请检查网络！", Toast.LENGTH_SHORT).show();
        } else {
            if (isDeleteImage) {
                progressUtil.ShowProgress(context, true, true, "图片删除中");
            } else {
                if (isNewListUpdate) {
                    progressUtil.ShowProgress(context, true, true, "图片上传中");
                }
            }

            HttpUtils httpUtils = new HttpUtils(10000);
            RequestParams params = new RequestParams();
            if (imagePath.equals("")) {
                params.addBodyParameter("uploadImage", "");
            } else {
                params.addBodyParameter("uploadImage", new File(imagePath));
            }
            String oldname = App.getDBcApplication().getTitleOldImagePath(maxTitleId);
            params.addBodyParameter("uId", userid);
            params.addBodyParameter("uploadImageFileName", imageName);
            params.addBodyParameter("oldName", "");
            params.addBodyParameter("type", "2");
            params.addBodyParameter("titleId", "" + id);
            params.addBodyParameter("title", Title);
            httpUtils.send(HttpMethod.POST, URLConstants.清单上行图片, params,
                    new RequestCallBack<String>() {

                        @Override
                        public void onFailure(HttpException e, String msg) {
                            progressUtil.dismiss();
                            if (isDeleteImage) {
                                Toast.makeText(context, "删除失败！", Toast.LENGTH_SHORT).show();
                            } else {
                                Toast.makeText(context, "上传失败！", Toast.LENGTH_SHORT).show();
                            }
                        }

                        @Override
                        public void onSuccess(ResponseInfo<String> responseInfo) {
                            progressUtil.dismiss();
                            if (!TextUtils.isEmpty(responseInfo.result)) {
                                Gson gson = new Gson();
                                UploadImageBean bean = gson.fromJson(responseInfo.result, UploadImageBean.class);
                                if (bean.status == 0) {
                                    UploadImageBean.ListBean listBean = bean.list.get(0);
                                    path = listBean.path;
                                    App.getDBcApplication().updateNoteTitleImage(maxTitleId, userid, listBean.path, isNewList);
//                                    App.getDBcApplication().updateTitleState(listBean.titleId, 2);
                                    setHeaderImage(listBean.path);
//                                    isNewListUpdate = true;
                                } else {
                                    Toast.makeText(context, "上传失败！", Toast.LENGTH_SHORT).show();
                                }
                            } else {
                                if (isDeleteImage) {
                                    Toast.makeText(context, "删除失败！", Toast.LENGTH_SHORT).show();
                                } else {
                                    Toast.makeText(context, "上传失败！", Toast.LENGTH_SHORT).show();
                                }
                            }
                        }
                    });

        }
    }

    /**
     * 插入标题图片
     *
     * @param path
     */
    public void setHeaderImage(String path) {
        for (CalenderNoteBean.PageBean.ItemsBean bean : list) {
            bean.imgPath = path;
        }
        isNOTETB = true;
        App.getDBcApplication().updateCalenderNoteTitleImage(maxTitleId, userid, path, isNewList);
//        App.getDBcApplication().updateTitleState(maxTitleId, 2);
        showTitleImage(path);
    }

    private void showTitleImage(String path) {
        if (path != null) {
            if (!path.equals("")) {
                header_image_flag = true;

                String dicr = Environment.getExternalStorageDirectory() + "/DCIM/";
                File outfile = new File(dicr, "TimeApp");
                // 如果文件不存在，则创建一个新文件
                if (!outfile.isDirectory()) {
                    try {
                        outfile.mkdir();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

                Bitmap bitmap = BitmapFactory.decodeFile(outfile + "/" + path.replace('/', '0'));

                if (bitmap == null) {
                    final DisplayImageOptions options = new DisplayImageOptions.Builder()
                            .showStubImage(R.mipmap.loads)          // 设置图片下载期间显示的图片
                            .showImageForEmptyUri(R.mipmap.loads)  // 设置图片Uri为空或是错误的时候显示的图片
                            .showImageOnFail(R.mipmap.loads)       // 设置图片加载或解码过程中发生错误显示的图片
                            .cacheInMemory(true)                        // 设置下载的图片是否缓存在内存中
                            .cacheOnDisc(true)                          // 设置下载的图片是否缓存在SD卡中
                            .build();
                    final String imageUrl = URLConstants.图片 + path + "&imageType=15&imageSizeType=1";
                    ImageLoader.getInstance().displayImage(imageUrl, header_image, options);
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            ImageLoader.getInstance().displayImage(imageUrl, header_image, options);
                        }
                    }, 2000);
                    Intent intent = new Intent(context, DownImageService.class);
                    intent.setAction("downimage");
                    intent.putExtra("url", imageUrl);
                    intent.putExtra("name", path.replace('/', '0'));
                    startService(intent);
                } else {
                    header_image.setImageBitmap(bitmap);
                }


                header_image.setVisibility(View.VISIBLE);
//                image_line.setVisibility(View.GONE);

            } else {
                header_image_flag = false;
                header_image.setVisibility(View.GONE);
//                image_line.setVisibility(View.VISIBLE);

            }
        } else {
            header_image_flag = false;
//            image_line.setVisibility(View.VISIBLE);
            header_image.setVisibility(View.GONE);
        }
    }

    String paths;
    private String mOutputPath;
    private String mDemoPath;
    Bitmap bitmap = null;

    boolean isNOTETB = false;

    private void copyRepeatChild() {
        if (!isNewList && (!schRepeatID.equals("0")) && isRepeatEidt) {
            for (int i = 0; i < list.size(); i++) {
                list.get(i).setTitleId(maxTitleId);
                list.get(i).setId(App.getDBcApplication().getCalenderMinId() - 1);
                App.getDBcApplication().saveCalederNoteDetailData(list.get(i));
                App.getDBcApplication().updateCalenderNoteDetailState(maxTitleId, list.get(i).id, userid, 1, true);
            }
        }
    }

    @Override
    public void onBackPressed() {
        imm.hideSoftInputFromWindow(editTextC.getWindowToken(), 0);

        Log.e("TAG", "-------------------------1");

        if (header_image_flag) {
            if (editTextC.getText().toString().trim().isEmpty()) {
                editTextC.setText("无标题");
            }
        }
        Log.e("TAG", "-------------------------2");
        if (list.size() > 0) {
            if (schRepeatID.equals("0")) {
                updateList();
                deleteEmpty();
            }
            if (editTextC.getText().toString().trim().isEmpty()) {
                editTextC.setText("无标题");
            }
        }
        Log.e("TAG", "-------------------------3");
        if (editTextC.getText().toString().equals("")) {
            ExitDailog();
        } else {
            if (isNewList) {
                if (!editTextC.getText().toString().trim().isEmpty()) {
                    int schColocType = 0;
                    int schImporttant = 0;
                    switch (newopeartType) {
                        case -2:
                            schImporttant = 1;
                            break;
                        case -3:
                            schIsPostpone = 1;
                            shun.setChecked(true);
                            break;
                        case -6:
                        case -7:
                        case -8:
                        case -9:
                        case -10:
                        case -11:
                        case -12:
                            schColocType = Math.abs(newopeartType) - 5;
                            break;
                    }
                    sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.SCHTYPE, "1");
                    schID = (App.getDBcApplication().getScheduleTableMinId() - 1)+"";
                    if (newopeartType == -4) {
                        App.getDBcApplication().insertScheduleData(editTextC.getText().toString() + " (到期日 " + calender_date.getText().toString() + ")"
                                , calender_date.getText().toString(), schTime, isAlarm, schBeforeTime,
                                schDisplayTime, schIsPostpone, schImporttant, schColocType, 0,
                                calender_date.getText().toString() + " " + schTime + ":00", "",
                                2, maxTitleId, stylee + "", 0, "", "",
                                1, 0, 0, lingshengnames, lingshengcode, "", 0, 0, 0, "", path, 0, 0, -1, 0, schRemark1, "0", "0");
                    } else {
                        App.getDBcApplication().insertScheduleData(editTextC.getText().toString(),
                                calender_date.getText().toString(), schTime, isAlarm, schBeforeTime,
                                schDisplayTime, schIsPostpone, schImporttant, schColocType, 0,
                                calender_date.getText().toString() + " " + schTime + ":00", "",
                                2, maxTitleId, stylee + "", 0, "", "",
                                1, 0, 0, lingshengnames, lingshengcode, "", 0, 0, 0, "", path, 0, 0, 0, 0, schRemark1, "0", "0");
                    }
                    Toast.makeText(context, "新建成功", Toast.LENGTH_SHORT).show();
                }
            } else {
                sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.SCHTYPE, "1");
                App.getDBcApplication().updateScheduleCalenderNoteData(
                        schID,
                        editTextC.getText().toString(),
                        calender_date.getText().toString(), schTime,
                        isAlarm, schBeforeTime, schDisplayTime,
                        schIsPostpone, lingshengnames, lingshengcode, path, maxTitleId, stylee, Integer.valueOf(schRepeatID));
                //重复ID存在，编辑标记TURE，子记事脱钩，生成下一条
                if (!schRepeatID2.equals("0") && isRepeatEidt) {
                    App.getDBcApplication().updateSchuledRepeatTo(schID);
                    Map<String, String> maprepeat = App.getDBcApplication().QueryhongFuData(schRepeatID2);
                    if (maprepeat != null) {
                        if ("0".equals(maprepeat.get(CLRepeatTable.repInSTable))
                                && "0".equals(maprepeat.get(CLRepeatTable.repIsPuase))) {

                            if (!App.getDBcApplication().queryChildRepeatIsSave(
                                    maprepeat.get(CLRepeatTable.repContent),
                                    maprepeat.get(CLRepeatTable.repNextCreatedTime),
                                    maprepeat.get(CLRepeatTable.repID))) {
                                DownRepeatService.CreateRepeatSchNextData(maprepeat);

                                QueryAlarmData.writeAlarm(context);
                            }
                        }
                    }
                }
            }

            if (list.size() > 0) {
                StringBuilder remark12 = new StringBuilder();
                for (int i = 0; i < list.size(); i++) {
                    CalenderNoteBean.PageBean.ItemsBean listBean = list.get(i);
                    if (!listBean.contents.isEmpty()) {
                        if (stylee == 0) {
                            if (listBean.endstate == 0) {
                                remark12.append("□ ").append(listBean.contents);
                            } else {
                                remark12.append("▣ ").append(listBean.contents);
                            }
                        } else if (stylee == 1) {
                            remark12.append("• ").append(listBean.contents);
                        } else if (stylee == 2) {
                            remark12.append(listBean.orderId).append(".").append(listBean.contents);
                        } else if (stylee == 3) {
                            remark12.append("• ").append(listBean.contents);
                        } else if (stylee == 4) {
                            if (listBean.endstate == 0) {
                                remark12.append("○ ").append(listBean.contents);
                            } else if (listBean.endstate == 1) {
                                remark12.append("☉ ").append(listBean.contents);
                            } else {
                                remark12.append("● ").append(listBean.contents);
                            }
                        }
                    }
                    if (i > 5) {
                        break;
                    }
                }
                App.getDBcApplication().updateScheduleTableschRemark12(" "+remark12.toString(), schID);
            }

            if (schRemark1.equals("1")) {
                ShareUrlDelete();
                uploadCalendernote();
            }
            Log.e("TAG", "-------------------------4");
            QueryAlarmData.writeAlarm(context);
            this.finish();
        }
    }

    private void ExitDailog() {
        final android.app.AlertDialog builder = new android.app.AlertDialog.Builder(context).create();

        builder.show();
        Window window = builder.getWindow();
        android.view.WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        params.alpha = 0.92f;
        window.setAttributes(params);// 设置生效
        window.setContentView(R.layout.dialog_alter);
        TextView delete_ok = window.findViewById(R.id.delete_ok);
        delete_ok.setText("继续编辑");
        delete_ok.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                builder.dismiss();
            }
        });
        TextView cancle_tv = window.findViewById(R.id.cancle_tv);
        cancle_tv.setText("确认返回");
        cancle_tv.setTextColor(Color.RED);
        cancle_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                builder.dismiss();
                finish();
            }
        });
        TextView delete_tv = window.findViewById(R.id.delete_tv);


        delete_tv.setText("无文本信息不能保存");

    }


    private void ShareUrlDelete() {
        try {
            mMap = App.getDBcApplication().querayOneCalenderData(Integer.valueOf(schID));
            final JSONObject data = new JSONObject();
            JSONArray timetable = new JSONArray();
            JSONObject json = new JSONObject();
            json.put("updateState", 2);
            json.put("uid", "");
            json.put("puid", userid);
            json.put("pname", sharedPrefUtil.getString(ShareFile.USERNAME, ""));
            json.put("ptitleimg", path);
            json.put("titleId", maxTitleId);
            json.put("cdate", calender_date.getText().toString());
            json.put("ctime", schTime);
            json.put("content", editTextC.getText().toString());
            json.put("cisEnd", mMap.get(ScheduleTable.schIsEnd));
            json.put("cdisplayAlarm", schDisplayTime);
            json.put("cisAlarm", isAlarm);
            json.put("cbefortime", schBeforeTime);
            json.put("calarmsound", lingshengcode);
            json.put("calarmsoundDesc", lingshengnames);
            json.put("cpostpone", schIsPostpone);
            json.put("cimportant", mMap.get(ScheduleTable.schIsImportant));
            json.put("cscore", "0");
            json.put("changeTime", DateUtil.nowTime());
            json.put("createTime", mMap.get(ScheduleTable.schCreateTime).replace('T', ' '));
            json.put("remark", "");
            json.put("remark1", "");
            json.put("remark2", "");
            json.put("remark3", "");
            json.put("remark4", "");
            json.put("remark5", "");
            timetable.put(json);
            data.put("timetable", timetable);


            StringRequest request4 = new StringRequest(Request.Method.POST, URLConstants.同步临时表数据, new Response.Listener<String>() {
                @Override
                public void onResponse(String s) {
                }


            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {

                }
            }) {
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("data", data.toString());
                    return map;
                }
            };
            request4.setTag("同步临时表数据");
            request4.setRetryPolicy(new DefaultRetryPolicy(5000, 1, 1.0f));
            App.getHttpQueues().add(request4);

            uploadCalendernote();
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    int schIsPostpone = 0;
    int schDisplayTime = 0;

    Set<Integer> copy_child_set = new HashSet<>();

    /**
     * 排序和返回之前重新获取一次数据
     */
    private void updateList() {
        int count = mEditTextList.getChildCount();
        if (count > 0) {
            if (count == list.size()) {
                for (int i = 0; i < mEditTextList.getChildCount(); i++) {

                    ((EditTextC) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text)).setIndex(i);
                    ((TextView) mEditTextList.getChildAt(i).findViewById(R.id.xh)).setText((i + 1) + ". ");
                    ((CheckBoxC) mEditTextList.getChildAt(i).findViewById(R.id.ch)).setIndex(i);
                    ((TextViewC) mEditTextList.getChildAt(i).findViewById(R.id.tv_gd)).setIndex(i);
                    ((TextViewC) mEditTextList.getChildAt(i).findViewById(R.id.tv_delete)).setIndex(i);
                    ((CButton) mEditTextList.getChildAt(i).findViewById(R.id.santai_button)).setIndex(i);
                    App.getDBcApplication().updateCalenderNoteDetailEndstate(list.get(i).id, list.get(i).endstate, maxTitleId, userid, isNewList);
                    App.getDBcApplication().updateCalenderNoteDetailOrderId(i + 1, list.get(i).id, maxTitleId, userid, isNewList);

                    String s = ((EditTextC) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text)).getText().toString();
                    //修改修改时间
                    App.getDBcApplication().updateCalenderNoteDetail(list.get(i).id, maxTitleId, userid, s, DateUtil.nowTime(), isNewList);
                    //如果是新建清单,状态为1,反之为2
//                    if (isNewList) {
//                        App.getDBcApplication().UpdateQdUpdateState(list.get(i).id, 1);
//                    } else {
//                        App.getDBcApplication().UpdateQdUpdateState(list.get(i).id, 2);
//                    }
                    list.get(i).contents = s;
                    list.get(i).orderId = i + 1;
                }
            }
        }


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (requestCode == 601) {
            addcopy = sharedPrefUtil.getString(context, ShareFile.USERFILE,
                    ShareFile.ADDQDCOPY, "1");//1底部2顶部
            addicon = sharedPrefUtil.getString(context, ShareFile.USERFILE,
                    ShareFile.ADDQDICON, "0");
            for (CalenderNoteBean.PageBean.ItemsBean bean : list) {
                bean.ltype = Integer.valueOf(addicon);
//                bean.remark = addcopy;
            }
            App.getDBcApplication().updateNoteTitleIconCopy(Integer.valueOf(addicon), addcopy, maxTitleId, userid, isNewList);
//            }
//            if (!isNewList) {
//                App.getDBcApplication().updateTitleState(maxTitleId, 2);
//            }
            isNOTETB = true;
        }

        if (requestCode == 602) {
            list.clear();
            list = App.getDBcApplication().getCalenderNoteDetailData(userid, maxTitleId, false);

            px();
            isNOTETB = false;

        }
        if (requestCode == 603) {
            if (resultCode == Activity.RESULT_OK) {
                Bundle bundle = data.getExtras();
                List<CalenderNoteBean.PageBean.ItemsBean> listmap = (List<CalenderNoteBean.PageBean.ItemsBean>) bundle.getSerializable("pxlist");
                list.clear();
                list.addAll(listmap);
                if (!isNewList) {
                    App.getDBcApplication().updateCalenderNoteDetailOrderId(maxTitleId, userid);
                }
                px();
                isNOTETB = true;
            }
        }

        if (requestCode == 604) {
            if (resultCode == 1) {
                isNOTETB = true;
                Toast.makeText(context, "复制成功", Toast.LENGTH_SHORT).show();
            }
        }
        if (requestCode == 605) {
            if (resultCode == 1) {
                isNOTETB = true;
                if (mEditTextList.getChildCount() > 1) {
                    App.getDBcApplication().deleteCalenderNoteDetail(list.get(moreindex).id, maxTitleId, userid, isNewList);

                    list.remove(moreindex);
                    mEditTextList.removeViewAt(moreindex);


                    int childcount = mEditTextList.getChildCount();
                    if (childcount > 0) {
                        for (int i = 0; i < mEditTextList.getChildCount(); i++) {
                            ((EditTextC) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text)).setIndex(i);
                            ((TextView) mEditTextList.getChildAt(i).findViewById(R.id.xh)).setText((i + 1) + ". ");
                            ((CheckBoxC) mEditTextList.getChildAt(i).findViewById(R.id.ch)).setIndex(i);
                            ((TextViewC) mEditTextList.getChildAt(i).findViewById(R.id.tv_gd)).setIndex(i);
                            ((TextViewC) mEditTextList.getChildAt(i).findViewById(R.id.tv_delete)).setIndex(i);
                            ((CButton) mEditTextList.getChildAt(i).findViewById(R.id.santai_button)).setIndex(i);
                            App.getDBcApplication().updateCalenderNoteDetailEndstate(list.get(i).id, list.get(i).endstate, maxTitleId, userid, isNewList);
                            App.getDBcApplication().updateCalenderNoteDetailOrderId(i, list.get(i).id, maxTitleId, userid, isNewList);
//                            if (!isNewList) {
//                                App.getDBcApplication().updateNoteTitleDetailState(maxTitleId, list.get(i).id, userid, 2, false);
//                            }
                        }
                    }
                } else {
                    ((EditTextC) mEditTextList.getChildAt(0).findViewById(R.id.et_edit_text)).setText("");
                    list.get(onFouns).contents = "";
                    list.get(onFouns).changeTime = DateUtil.nowTime();
                    //修改修改时间
                    App.getDBcApplication().updateCalenderNoteDetail(list.get(onFouns).id, maxTitleId, userid, "", list.get(onFouns).changeTime, isNewList);

                }
                Toast.makeText(context, "移动成功", Toast.LENGTH_SHORT).show();
            }
        }
        if (resultCode == Activity.RESULT_OK) {
            if (data != null) {
                String fileName = "HeaderImage_" + String.valueOf(System.currentTimeMillis()) + ".png";

                Uri selectImageUri = data.getData();

                if (selectImageUri != null) {
                    Uri mDestinationUri = Uri.fromFile(new File(getCacheDir(), fileName));
                    UCrop uCrop = UCrop.of(selectImageUri, mDestinationUri);
                    if (isLongJTImage == 1) {
                        uCrop.withAspectRatio(4, 3);
                    }
                    UCrop.Options options = new UCrop.Options();
                    options.setHideBottomControls(true);
                    options.setCompressionQuality(50);
                    uCrop.withOptions(options);
                    uCrop.start(CalenderNoteEditActivity.this);
                }


                if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
                    final Uri resultUri = UCrop.getOutput(data);
                    String path = RxPhotoUtils.getRealFilePath(context, resultUri);
                    if (path != null) {
                        paths = path;
                        int imageHeight = ImageUtils.getImageHeight(paths);
                        Bitmap bitmap = BitmapFactory.decodeFile(paths);
                        if (bitmap != null) {
                            if (NetUtil.getConnectState(context) != NetWorkState.NONE) {
                                isDeleteImage = false;
                                header_image.setVisibility(View.VISIBLE);
                                Bitmap b = BitmapFactory.decodeResource(getResources(), R.mipmap.loads);
                                header_image.setImageBitmap(b);
                                upimage(paths, fileName);
                            } else {
                                alertFailDialog("请检查您的网络！");
                            }
                        } else {
                            alertFailDialog("图片上传失败！");
                        }
                    }
                } else if (resultCode == UCrop.RESULT_ERROR) {
                    Toast.makeText(context, "图片裁剪失败", Toast.LENGTH_SHORT).show();
                }
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }


    //新建的清单是否已经上传
    boolean isNewListUpdate = false;

    /**
     * 上传图片上传清单数据
     */
//    public void uploadlist(String imagePath, String imageName) {
//        List<NoteTitleDetailBean.TDelListBean> tDelListBeanList = App.getDBcApplication().getAllNoteTitlesData(userid, true);
////        isNewListUpdate = App.getDBcApplication().getNoteTitleUpdateState(maxTitleId, userid);
//        isNewListUpdate = false;
//        if (!isNewListUpdate) {
//            progressUtil.ShowProgress(context, true, true, "清单同步中...");
//            JSONObject tDelListBeanListjsonObject = new JSONObject();
//            try {
//                JSONArray tDelListBeanListjsonArray = new JSONArray();
//                for (NoteTitleDetailBean.TDelListBean bean : tDelListBeanList) {
//                    JSONObject js = new JSONObject();
//                    js.put("id", bean.id);
//                    js.put("titleId", bean.titleId);
//                    js.put("uid", bean.uid);
//                    js.put("titles", bean.titles);
//                    js.put("imgPath", bean.imgPath);
//                    js.put("imgUrl", bean.imgUrl);
//                    js.put("shareUrl", bean.shareUrl);
//                    js.put("filed", bean.filed);
//                    js.put("nums", bean.nums);
//                    js.put("copys", bean.copys);
//                    js.put("styles", bean.styles);
//                    js.put("ltype", bean.ltype);
//                    js.put("orderId", bean.orderId);
//                    js.put("createTime", bean.createTime);
//                    js.put("changeTime", bean.changeTime);
//                    js.put("localTimes", bean.localTimes);
//                    js.put("remark", bean.remark);
//                    js.put("remark1", bean.remark1);
//                    js.put("remark2", bean.remark2);
//                    js.put("remark3", bean.remark3);
//                    js.put("puid", bean.puid);
//                    js.put("pname", bean.pname);
//                    js.put("states", bean.states);
//                    js.put("sends", bean.sends);
//                    js.put("openState", bean.openState);
//                    js.put("updateState", bean.id < 0 ? 1 : App.getDBcApplication().getNoteTitleState(bean.titleId, userid));
//                    tDelListBeanListjsonArray.put(js);
//                }
//
//                if (tDelListBeanList.size() > 0) {
//                    tDelListBeanListjsonObject.put("classTitle", tDelListBeanListjsonArray);
//                } else {
//                    tDelListBeanListjsonObject = null;
//                }
//            } catch (JSONException e) {
//                e.printStackTrace();
//            }
//            //详情
//            List<NoteTitleDetailBean.ListBean> listBeanList = App.getDBcApplication().getAllNoteDetailData(userid, true);
//            JSONObject listjsonObject = new JSONObject();
//            try {
//                JSONArray listjsonArray = new JSONArray();
//                for (NoteTitleDetailBean.ListBean bean : listBeanList) {
//                    JSONObject js = new JSONObject();
//                    js.put("id", bean.id);
//                    js.put("titleId", bean.titleId);
//                    js.put("uid", bean.uid);
//                    js.put("titles", bean.titles);
//                    js.put("imgPath", bean.imgPath);
//                    js.put("imgUrl", bean.imgUrl);
//                    js.put("shareUrl", bean.shareUrl);
//                    js.put("contents", bean.contents);
//                    js.put("nums", bean.nums);
//                    js.put("style", bean.style);
//                    js.put("endstate", bean.endstate);
//                    js.put("lType", bean.lType);
//                    js.put("orderId", bean.orderId);
//                    js.put("createTime", bean.createTime);
//                    js.put("changeTime", bean.changetime);
//                    js.put("cpath", bean.cpath);
//                    js.put("curl", bean.curl);
//                    js.put("remark", bean.remark);
//                    js.put("remark1", bean.remark1);
//                    js.put("remark2", bean.remark2);
//                    js.put("remark3", bean.remark3);
//                    js.put("remark4", bean.remark4);
//                    js.put("updateState", bean.id < 0 ? 1 : App.getDBcApplication().getNoteTitleDetailState(bean.titleId, userid, bean.id));
//                    listjsonArray.put(js);
//                }
//                if (listBeanList.size() > 0) {
//                    listjsonObject.put("class1", listjsonArray);
//                } else {
//                    listjsonObject = null;
//                }
//
//            } catch (JSONException e) {
//                e.printStackTrace();
//            }
//            uploadListData(listjsonObject == null ? "" : listjsonObject.toString(), tDelListBeanListjsonObject == null ? "" : tDelListBeanListjsonObject.toString(), imagePath, imageName);
//        } else {
//            upimage(imagePath, imageName);
//        }
//    }
    private void sharetofaxian() {
        if (NetUtil.getConnectState(this) == NetWorkState.NONE) {
            Toast.makeText(context, "网络异常，请检查网络！", Toast.LENGTH_SHORT).show();
        } else {
            try {
                List<CalenderNoteBean.PageBean.ItemsBean> listBeanList = App.getDBcApplication().getCalenderNoteDetailData(userid, maxTitleId, false);
                JSONObject jsonObject = new JSONObject();
                JSONArray jsonArray = new JSONArray();
                String title_share;
                if (listBeanList.size() > 0) {
                    title_share = listBeanList.get(0).titles;

                    if (title_share.isEmpty()) {
                        String con = listBeanList.get(0).contents;
                        title_share = con.length() > 15 ? con.substring(0, 15) : con;
                    }

                    for (CalenderNoteBean.PageBean.ItemsBean bean : listBeanList) {
                        if (!bean.contents.isEmpty()) {
                            JSONObject js = new JSONObject();
                            js.put("id", bean.id);
                            js.put("titleId", bean.titleId);
                            js.put("uid", bean.uid);
                            js.put("titles", title_share);
                            js.put("imgPath", bean.imgPath);
                            js.put("imgUrl", bean.imgUrl);
                            js.put("shareUrl", bean.shareUrl);
                            js.put("contents", bean.contents);
                            js.put("nums", bean.nums);
                            js.put("style", bean.style);
                            js.put("endstate", bean.endstate);
                            js.put("lType", bean.ltype);
                            js.put("orderId", bean.orderId);
                            js.put("createTime", bean.createTime);
                            js.put("changeTime", bean.changeTime);
                            js.put("cpath", bean.cpath);
                            js.put("curl", bean.curl);
                            js.put("remark", bean.remark);
                            js.put("remark1", bean.remark1);
                            js.put("remark2", bean.remark2);
                            js.put("remark3", bean.remark3);
                            js.put("remark4", bean.remark4);
                            js.put("remark5", bean.remark5);
                            js.put("remark6", bean.remark6);
                            js.put("sdesc", bean.sdesc);
                            js.put("localIds", bean.localIds);
                            jsonArray.put(js);
                        }
                    }
                    if (listBeanList.size() > 0) {
                        jsonObject.put("class1", jsonArray);
                    } else {
                        jsonObject = null;
                    }

                    HttpUtils httpUtils = new HttpUtils(10000);
                    RequestParams params = new RequestParams();
                    params.addBodyParameter("oldName", sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERNAME, ""));
                    params.addBodyParameter("data", jsonObject == null ? "" : jsonObject.toString());
                    httpUtils.send(HttpMethod.POST, URLConstants.清单分享发现, params,
                            new RequestCallBack<String>() {

                                @Override
                                public void onFailure(HttpException e, String msg) {
                                    Toast.makeText(context, "分享失败", Toast.LENGTH_SHORT).show();
                                }

                                @Override
                                public void onSuccess(ResponseInfo<String> responseInfo) {
                                    if (!TextUtils.isEmpty(responseInfo.result)) {

                                        Gson gson = new Gson();
                                        ShareBean shareBean = gson.fromJson(responseInfo.result, ShareBean.class);
                                        if (shareBean.status == 0) {
                                            if (shareBean.list.size() > 0) {
                                                App.getDBcApplication().updateCalenderNoteNums(maxTitleId, userid, shareBean.list.get(0).num);
                                            }
                                            Toast.makeText(context, "分享成功", Toast.LENGTH_SHORT).show();
                                        } else {
                                            Toast.makeText(context, "分享失败", Toast.LENGTH_SHORT).show();
                                        }

                                    } else {
                                        Toast.makeText(context, "分享失败", Toast.LENGTH_SHORT).show();
                                    }

                                }
                            });
                } else {
                    Toast.makeText(context, "请输入写清单内容再来分享吧", Toast.LENGTH_SHORT).show();
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }


    class ShareBean {


        /**
         * delList : null
         * downTime : 2017-06-27T11:20:23
         * list : [{"num":"20170627112023959592","state":0}]
         * message : 成功
         * status : 0
         * tDelList : null
         */

        public Object delList;
        public String downTime;
        public String message;
        public int status;
        public Object tDelList;
        public List<ListBean> list;

        public Object getDelList() {
            return delList;
        }

        public void setDelList(Object delList) {
            this.delList = delList;
        }

        public String getDownTime() {
            return downTime;
        }

        public void setDownTime(String downTime) {
            this.downTime = downTime;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public Object getTDelList() {
            return tDelList;
        }

        public void setTDelList(Object tDelList) {
            this.tDelList = tDelList;
        }

        public List<ListBean> getList() {
            return list;
        }

        public void setList(List<ListBean> list) {
            this.list = list;
        }

        public class ListBean {
            /**
             * num : 20170627112023959592
             * state : 0
             */

            public String num;
            public int state;

            public String getNum() {
                return num;
            }

            public void setNum(String num) {
                this.num = num;
            }

            public int getState() {
                return state;
            }

            public void setState(int state) {
                this.state = state;
            }
        }
    }


    /**
     * 上传清单数据
     *
     * @param
     */
//
//    private void uploadListData(String data, String dataTitle, final String imagePath, final String imageName) {
//        if (NetUtil.getConnectState(this) == NetWorkState.NONE) {
//            Toast.makeText(context, "网络异常，请检查网络！", Toast.LENGTH_SHORT).show();
//        } else {
//            HttpUtils httpUtils = new HttpUtils(10000);
//            RequestParams params = new RequestParams();
//            params.addBodyParameter("data", data);
//            params.addBodyParameter("dataTitle", dataTitle);
//            httpUtils.send(HttpMethod.POST, URLConstants.清单和清单标题上行, params,
//                    new RequestCallBack<String>() {
//
//                        @Override
//                        public void onFailure(HttpException e, String msg) {
//                            if (!isNewListUpdate) {
//                                progressUtil.dismiss();
//                                Toast.makeText(context, "同步失败", Toast.LENGTH_SHORT).show();
//                            }
//                        }
//
//
//                        @Override
//                        public void onSuccess(ResponseInfo<String> responseInfo) {
//                            if (!TextUtils.isEmpty(responseInfo.result)) {
//                                Gson gson = new Gson();
//                                NoteService.noteSynBean bean = gson.fromJson(responseInfo.result, NoteService.noteSynBean.class);
//                                if (bean.status == 0) {
//                                    List<NoteService.noteSynBean.TDelListBean> tDeListBeanList = bean.tDelList;
//
//                                    //标题同步没有异常
//                                    List<Integer> errorList = new ArrayList<Integer>();
//
//                                    for (NoteService.noteSynBean.TDelListBean tDeListBean : tDeListBeanList) {
//                                        if (tDeListBean.dataState == 1) {//新增
//                                            if (tDeListBean.state == 0) {//成功
//                                                //修改id和状态值
//                                                App.getDBcApplication().updateNoteTitleId(tDeListBean.id, tDeListBean.calendId, userid);
//                                                App.getDBcApplication().updateNoteTitleState(tDeListBean.calendId + "", userid, 0, true);
//                                                if (!isNewListUpdate) {
//                                                    upimage(imagePath, imageName);
//                                                }
//                                            } else if (tDeListBean.state == 1) {//失败  可以不操作,但是避免意外
//                                                //更改状态为1
//                                                App.getDBcApplication().updateNoteTitleState(tDeListBean.id + "", userid, 1, true);
//                                            } else if (tDeListBean.state == 2) { //异常
//                                                App.getDBcApplication().updateNoteTitleState(tDeListBean.id + "", userid, -1, true);
//                                                errorList.add(tDeListBean.id);
//                                            }
//                                        } else if (tDeListBean.dataState == 2) {//修改
//                                            if (tDeListBean.state == 0) {//成功
//                                                //修改该id状态值
//                                                App.getDBcApplication().updateNoteTitleState(tDeListBean.id + "", userid, 0, true);
//                                            } else if (tDeListBean.state == 1) {//失败
//                                                //更改状态为2
//                                                App.getDBcApplication().updateNoteTitleState(tDeListBean.id + "", userid, 2, true);
//                                            } else if (tDeListBean.state == 2) { //异常
//                                                App.getDBcApplication().updateNoteTitleState(tDeListBean.id + "", userid, -1, true);
//                                                errorList.add(tDeListBean.id);
//                                            }
//                                        } else if (tDeListBean.dataState == 3) {//删除
//                                            if (tDeListBean.state == 0) {//成功
//                                                //删除该id的清单
//                                                App.getDBcApplication().deleteNoteTitleData(tDeListBean.id, userid, false);
//                                            } else if (tDeListBean.state == 1) {//失败
//                                                //更改状态为3
//                                                App.getDBcApplication().updateNoteTitleState(tDeListBean.id + "", userid, 3, true);
//                                            } else if (tDeListBean.state == 2) { //异常
//                                                App.getDBcApplication().updateNoteTitleState(tDeListBean.id + "", userid, -1, true);
//                                                errorList.add(tDeListBean.id);
//                                            }
//                                        }
//                                    }
//
//                                    if (errorList.size() == 0) {
//
//                                        List<NoteService.noteSynBean.ListBean> listBeans = bean.list;
//
//                                        for (NoteService.noteSynBean.ListBean listBean : listBeans) {
//
//                                            if (listBean.dataState == 1) {//新增
//                                                if (listBean.state == 0) {//成功
//                                                    //修改id和状态值
//                                                    App.getDBcApplication().updateNoteDetailId(listBean.id, listBean.calendId, userid);
//                                                    App.getDBcApplication().updateNoteTitleDetailState("", listBean.calendId, userid, 0, true);
//                                                } else if (listBean.state == 1) {//失败  可以不操作,但是避免意外
//                                                    //更改状态为1
//                                                    App.getDBcApplication().updateNoteTitleDetailState("", listBean.id, userid, 1, true);
//                                                } else if (listBean.state == 2) { //异常
//                                                    App.getDBcApplication().updateNoteTitleDetailState("", listBean.id, userid, -1, true);
//                                                }
//                                            } else if (listBean.dataState == 2) {//修改
//                                                if (listBean.state == 0) {//成功
//                                                    //修改该id状态值
//                                                    App.getDBcApplication().updateNoteTitleDetailState("", listBean.id, userid, 0, true);
//                                                } else if (listBean.state == 1) {//失败
//                                                    //更改状态为2
//                                                    App.getDBcApplication().updateNoteTitleDetailState("", listBean.id, userid, 2, true);
//                                                } else if (listBean.state == 2) { //异常
//                                                    App.getDBcApplication().updateNoteTitleDetailState("", listBean.id, userid, -1, true);
//                                                }
//                                            } else if (listBean.dataState == 3) {//删除
//                                                if (listBean.state == 0) {//成功
//                                                    //删除该id的清单
//                                                    App.getDBcApplication().deleteNoteTitledetailData(listBean.id, userid, false);
//                                                } else if (listBean.state == 1) {//失败
//                                                    //更改状态为3
//                                                    App.getDBcApplication().updateNoteTitleDetailState("", listBean.id, userid, 3, true);
//                                                } else if (listBean.state == 2) { //异常
//                                                    App.getDBcApplication().updateNoteTitleDetailState("", listBean.id, userid, -1, true);
//                                                }
//                                            }
//                                        }
//                                        sharedPrefUtil.putString(
//                                                getApplication(),
//                                                ShareFile.USERFILE,
//                                                ShareFile.DOWNREPTIME,
//                                                bean.downTime.replace(
//                                                        "T", " "));
//
//                                    }
//                                    Toast.makeText(context, "同步成功", Toast.LENGTH_SHORT).show();
//                                } else {
//                                    Toast.makeText(context, "同步失败", Toast.LENGTH_SHORT).show();
//                                }
//                                progressUtil.dismiss();
//                            }
//                        }
//                    });
//
//        }
//    }
    private void alertFailDialog(String meeage) {
        final AlertDialog builder = new AlertDialog.Builder(context).create();
        builder.show();
        Window window = builder.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        params.alpha = 0.92f;
        params.gravity = Gravity.CENTER;
        window.setAttributes(params);// 设置生效
        window.setGravity(Gravity.CENTER);
        window.setContentView(R.layout.dialog_alert_ok);
        TextView delete_ok = (TextView) window.findViewById(R.id.delete_ok);
        TextView delete_tv = (TextView) window.findViewById(R.id.delete_tv);

        delete_tv.setText(meeage);

        delete_ok.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                builder.cancel();
            }
        });

    }

    static boolean autoFag = false;
    private static final int RC_LOCATION_CONTACTS_PERM = 124;

    @AfterPermissionGranted(RC_LOCATION_CONTACTS_PERM)
    private void checkPhonePermission() {
        if (Build.VERSION.SDK_INT < 23) {
            autoFag = true;
        } else {
            String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE};
            if (EasyPermissions.hasPermissions(CalenderNoteEditActivity.this, perms)) {
                // Have permissions, do the thing!
                autoFag = true;
            } else {
                // Ask for both permissions
                EasyPermissions.requestPermissions(this, "该功能需要此权限，为了保证应用正常运行!",
                        RC_LOCATION_CONTACTS_PERM, perms);
            }
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        // EasyPermissions handles the request result.
        if (PackageManager.PERMISSION_GRANTED == grantResults[0]) {
            autoFag = true;
        } else {
            autoFag = false;
        }
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }

    @Override
    public void onPermissionsGranted(int requestCode, List<String> perms) {
        Log.d("TAG", "onPermissionsGranted:" + requestCode + ":" + perms.size());
    }

    @Override
    public void onPermissionsDenied(int requestCode, List<String> perms) {
// (Optional) Check whether the user denied permissions and checked NEVER ASK AGAIN.
        // This will display a dialog directing them to enable the permission in app settings.
        EasyPermissions.checkDeniedPermissionsNeverAskAgain(this,
                getString(R.string.rationale_ask_again),
                R.string.action_settings, R.string.cancel, null, perms);
    }


    /**
     * 分享长图
     *
     * @param imagepath
     */
    private void showShareLongImage(String imagepath) {
        ShareSDK.initSDK(this);
        OnekeyShare oks = new OnekeyShare();
        // 关闭sso授权
        oks.disableSSOWhenAuthorize();
        // imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
        oks.setImagePath(imagepath);//
        // 确保SDcard下面存在此张图片
        oks.show(this);
    }


    //分享其他
    private void showShare() {

        ShareSDK.initSDK(this);
        OnekeyShare oks = new OnekeyShare();
        // 关闭sso授权
        oks.disableSSOWhenAuthorize();
        oks.setTitle(editTextC.getText().toString());
        oks.setText(list.size() > 0 ? list.get(0).contents : editTextC.getText().toString());

        String url = "http://www.keytimeapp.com/qingdan/qdlist-fx.html?uid=" + userid + "$titleId=" +
                maxTitleId + "$id=" + schID + "$name=" + sharedPrefUtil.getString(context, ShareFile.USERFILE,
                ShareFile.USERNAME, "") + "$img=" + sharedPrefUtil.getString(context, ShareFile.USERFILE,
                ShareFile.USERPHOTOPATH, "");
        oks.setUrl(url);
        oks.setImageUrl(URLConstants.图片 + sharedPrefUtil.getString(context,
                ShareFile.USERFILE, ShareFile.USERPHOTOPATH, "") + "&imageType=2&imageSizeType=3");
        oks.setCallback(new newOneCallBack());
        // 启动分享GUI
        oks.show(this);
    }

    private void upLoadState() {
        boolean isSyn;
        progressUtil.dismiss();
        if (Integer.valueOf(schID) < 0) {
            isSyn = false;
        } else {
            isSyn = true;
        }
        if (isSyn) {
            if (isShare) {
//                IWXAPI api =  WXAPIFactory.createWXAPI(context, "wx5add723149fa57f5");
//                WXMiniProgramObject miniProgram = new WXMiniProgramObject();
//                miniProgram.webpageUrl="http://www.keytimeapp.com";//自定义
//                miniProgram.userName="gh_f297c56cae16";//小程序端提供参数
//                miniProgram.path="pages/schedule/schedule?uid="+userid+"&titleId="+maxTitleId+"&id="+schID+"&name="+name+"&img="+path;//小程序端提供参数
//                WXMediaMessage mediaMessage = new WXMediaMessage(miniProgram);
//                mediaMessage.title = Title2;//自定义
////                        String dicr = Environment.getExternalStorageDirectory() + "/DCIM/";
////                        File outfile = new File(dicr, "TimeApp");
////                        Bitmap bitmap = BitmapFactory.decodeFile(outfile + "/" + path.replace('/', '0'));
////                        if (bitmap == null) {
////                            bitmap = BitmapFactory.decodeResource(getResources(),R.mipmap.logo);
////                        }
//                mEditTextList.setBackgroundColor(Color.WHITE);
//                Bitmap bitmap = ImageUtils.convertViewToBitmap(mEditTextList);
//
//                mEditTextList.setBackgroundColor(Color.TRANSPARENT);
//                mediaMessage.thumbData = Util.bmpToByteArray(bitmap,true);
//                bitmap.recycle();
//                SendMessageToWX.Req req = new SendMessageToWX.Req();
//                req.transaction = "";
//                req.scene = SendMessageToWX.Req.WXSceneSession;
//                req.message = mediaMessage;
//                api.sendReq(req);
//                ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
//                // 将文本内容放到系统剪贴板里。
//                cm.setText("pages/schedule/schedule?uid="+userid+"&titleId="+maxTitleId+"&id="+schID+"&name="+name+"&img="+path);
//                Toast.makeText(context, "已复制", Toast.LENGTH_SHORT).show();
                Intent inten = new Intent(context, SelectionFirendActivity.class);
                inten.putExtra("schSourceType", "99");
                inten.putExtra("schRemark1", schRemark1);
                inten.putExtra("updateState", "1");
                inten.putExtra("schID", schID);
                inten.putExtra("titleid", maxTitleId);
                inten.putExtra("titles", "");
                inten.putExtra("remark6", "");
                inten.putExtra("remark5", "");
                startActivity(inten);
            } else {
                showShare();
            }
        } else {
            Toast.makeText(context, "数据未同步,无法分享", Toast.LENGTH_SHORT).show();
        }
    }

    private void upLoadData() {
        progressUtil.ShowProgress(context, true, true, "同步数据中...");
        if (isNewList) {
            if (!editTextC.getText().toString().trim().isEmpty()) {
                schID = (App.getDBcApplication().getScheduleTableMinId() - 1) + "";
                App.getDBcApplication().insertScheduleData(editTextC.getText().toString(),
                        calender_date.getText().toString(), schTime, isAlarm, schBeforeTime,
                        schDisplayTime, schIsPostpone, 0, 0, 0,
                        calender_date.getText().toString() + " " + schTime, "", 2, maxTitleId, "", 0, "", "",
                        1, 0, 0, lingshengnames, lingshengcode, "", 0, 0, 0, "", path, 0, 0, 0, 0, schRemark1, "0", "0");
                App.getDBcApplication().updateUpdateStateFaild(Integer.valueOf(schID), 1);
                QueryAlarmData.writeAlarm(context);
                Intent intentioned = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                Bundle extras = new Bundle();
                intentioned.putExtras(extras);
                sendBroadcast(intentioned);
                isNewList = false;
            }
        } else {
            if (!editTextC.getText().toString().trim().isEmpty()) {
                App.getDBcApplication().updateScheduleCalenderNoteData(
                        schID, editTextC.getText().toString(), calender_date.getText().toString(), schTime,
                        isAlarm, schBeforeTime, schDisplayTime, schIsPostpone, lingshengnames, lingshengcode,
                        path, maxTitleId, stylee, Integer.valueOf(schRepeatID));
                QueryAlarmData.writeAlarm(context);
                Intent intentioned = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                Bundle extras = new Bundle();
                intentioned.putExtras(extras);
                sendBroadcast(intentioned);
            }
        }
        try {
            List<Map<String, String>> upList = App.getDBcApplication().queryAllSchData(-1, 0, 0);
            JSONArray jsonarray = new JSONArray();
            JSONObject jsonobject = new JSONObject();
            for (int i = 0; i < upList.size(); i++) {
                if (upList.get(i).get(ScheduleTable.schSourceDesc).equals(maxTitleId)) {
                    JSONObject jsonobject1 = new JSONObject();
                    jsonobject1.put("tempId", upList.get(i).get(ScheduleTable.schID));
                    jsonobject1.put("cId", upList.get(i).get(ScheduleTable.schID));
                    jsonobject1.put("cRecommendId", upList.get(i).get(ScheduleTable.schcRecommendId));
                    jsonobject1.put("cUid", userid);
                    jsonobject1.put("cContent", upList.get(i).get(ScheduleTable.schContent));
                    jsonobject1.put("cDate", upList.get(i).get(ScheduleTable.schDate));
                    jsonobject1.put("cTime", upList.get(i).get(ScheduleTable.schTime));
                    jsonobject1.put("cIsAlarm", upList.get(i).get(ScheduleTable.schIsAlarm));
                    jsonobject1.put("cBeforTime", upList.get(i).get(ScheduleTable.schBeforeTime));
                    jsonobject1.put("cDisplayAlarm", upList.get(i).get(ScheduleTable.schDisplayTime));
                    jsonobject1.put("cPostpone", upList.get(i).get(ScheduleTable.schIsPostpone));
                    jsonobject1.put("cImportant", upList.get(i).get(ScheduleTable.schIsImportant));
                    jsonobject1.put("cColorType", upList.get(i).get(ScheduleTable.schColorType));
                    jsonobject1.put("cIsEnd", upList.get(i).get(ScheduleTable.schIsEnd));
                    jsonobject1.put("cCreateTime", upList.get(i).get(ScheduleTable.schCreateTime));
                    jsonobject1.put("cTags", upList.get(i).get(ScheduleTable.schTags));
                    jsonobject1.put("cType", upList.get(i).get(ScheduleTable.schSourceType));
                    jsonobject1.put("cTypeDesc", upList.get(i).get(ScheduleTable.schSourceDesc));
                    jsonobject1.put("cTypeSpare", upList.get(i).get(ScheduleTable.schSourceDescSpare));
                    jsonobject1.put("cRepeatId", upList.get(i).get(ScheduleTable.schRepeatID));
                    jsonobject1.put("cRepeatDate", upList.get(i).get(ScheduleTable.schRepeatDate));
                    jsonobject1.put("cUpdateTime", upList.get(i).get(ScheduleTable.schUpdateTime));
                    jsonobject1.put("cOpenState", upList.get(i).get(ScheduleTable.schOpenState));
                    jsonobject1.put("cRecommendName", upList.get(i).get(ScheduleTable.schcRecommendName));
                    jsonobject1.put("updateState", upList.get(i).get(ScheduleTable.schUpdateState));
                    jsonobject1.put("cAlarmSoundDesc", upList.get(i).get(ScheduleTable.schRingDesc));
                    jsonobject1.put("cAlarmSound", upList.get(i).get(ScheduleTable.schRingCode));
                    jsonobject1.put("schRead", upList.get(i).get(ScheduleTable.schRead));
                    jsonobject1.put("attentionid", upList.get(i).get(ScheduleTable.schAID));
                    jsonobject1.put("aType", upList.get(i).get(ScheduleTable.schAType));
                    jsonobject1.put("webUrl", upList.get(i).get(ScheduleTable.schWebURL));
                    jsonobject1.put("imgPath", upList.get(i).get(ScheduleTable.schImagePath));
                    jsonobject1.put("cSchRepeatLink", upList.get(i).get(ScheduleTable.schRepeatLink));
                    jsonobject1.put("pIsEnd", upList.get(i).get(ScheduleTable.schIsEnd));
                    jsonobject1.put("remark", upList.get(i).get(ScheduleTable.schRemark1));
                    jsonobject1.put("remark1", upList.get(i).get(ScheduleTable.schRemark2));
                    jsonobject1.put("remark2", upList.get(i).get(ScheduleTable.schRemark3));
                    jsonobject1.put("remark4", upList.get(i).get(ScheduleTable.schRemark4));
                    jsonobject1.put("remark5", upList.get(i).get(ScheduleTable.schRemark5));
                    jsonobject1.put("remark7", upList.get(i).get(ScheduleTable.schRemark7));
                    jsonobject1.put("remark10", upList.get(i).get(ScheduleTable.schRemark10));
                    jsonobject1.put("remark11", upList.get(i).get(ScheduleTable.schRemark11));
                    jsonobject1.put("remark12", upList.get(i).get(ScheduleTable.schRemark12));
                    jsonarray.put(jsonobject1);
                }
            }
            jsonobject.put("data", jsonarray);
            final String schjson = jsonobject.toString();
            String schuppath = "";
            if (sharedPrefUtil.getString(getApplicationContext(), ShareFile.USERFILE, ShareFile.UPLOADTYPE, "0").equals("1")) {
                schuppath = URLConstants.同步数据接口新;
            } else if (sharedPrefUtil.getString(getApplicationContext(), ShareFile.USERFILE, ShareFile.UPLOADTYPE, "0").equals("0")) {
                schuppath = URLConstants.同步数据接口2新;
            }

            StringRequest request = new StringRequest(Request.Method.POST, schuppath,
                    new Response.Listener<String>() {

                        @Override
                        public void onResponse(final String result) {
                            Log.e("TAG", result);
                            if (!TextUtils.isEmpty(result)) {
                                Gson gson = new Gson();
                                UpNew UpNew = gson.fromJson(result, UpNew.class);
                                List<UpNew.ListBean> listBeanList;
                                if (UpNew.status == 0) {
                                    listBeanList = UpNew.list;
                                    if (listBeanList != null) {
                                        if (listBeanList.size() > 0) {
                                            for (int i = 0; i < listBeanList.size(); i++) {
                                                if (listBeanList.get(i).dataState == 1) {//新增
                                                    if (schID.equals(listBeanList.get(i).id)) {
                                                        schID = listBeanList.get(i).calendId + "";
                                                    }
                                                    //新增成功就修改id和状态
                                                    if (listBeanList.get(i).state == 0) {//成功
                                                        App.getDBcApplication().UpdateSchID(Integer.parseInt(listBeanList.get(i).id), listBeanList.get(i).calendId);
                                                        App.getDBcApplication().updateUpdateState(listBeanList.get(i).calendId);
                                                        App.getDBcApplication().UpdateClockSchID(listBeanList.get(i).id, listBeanList.get(i).calendId + "");
                                                        schID = listBeanList.get(i).calendId + "";
                                                    } else if (listBeanList.get(i).state == 1) {//失败
                                                        com.mission.schedule.cutimage.Log.e("UPLOADCALENDER", listBeanList.get(i).calendId + ":FAILED");
                                                        App.getDBcApplication().updateUpdateStateFaild(listBeanList.get(i).calendId, 1);
                                                    } else if (listBeanList.get(i).state == 2) {
                                                        App.getDBcApplication().updateUpdateStateFaild(listBeanList.get(i).calendId, -1);
                                                    }
                                                } else if (listBeanList.get(i).dataState == 3) {//删除
                                                    //删除成功删除数据
                                                    if (listBeanList.get(i).state == 0) {
                                                        App.getDBcApplication().deleteScheduleData(listBeanList.get(i).calendId);
                                                    } else if (listBeanList.get(i).state == 1) {
                                                        com.mission.schedule.cutimage.Log.e("UPLOADCALENDER", listBeanList.get(i).calendId + ":FAILED");
                                                        App.getDBcApplication().updateUpdateStateFaild(listBeanList.get(i).calendId, 3);
                                                    } else if (listBeanList.get(i).state == 2) {
                                                        App.getDBcApplication().updateUpdateStateFaild(listBeanList.get(i).calendId, -1);
                                                    }
                                                    App.getDBcApplication().deleteSch(listBeanList.get(i).calendId);
                                                } else if (listBeanList.get(i).dataState == 2) {//修改
                                                    //修改成功修改状态
                                                    if (listBeanList.get(i).state == 0) {
                                                        App.getDBcApplication().updateUpdateState(listBeanList.get(i).calendId);
                                                    } else if (listBeanList.get(i).state == 1) {
                                                        com.mission.schedule.cutimage.Log.e("UPLOADCALENDER", listBeanList.get(i).calendId + ":FAILED");
                                                        App.getDBcApplication().updateUpdateStateFaild(listBeanList.get(i).calendId, 2);
                                                    } else if (listBeanList.get(i).state == 2) {
                                                        App.getDBcApplication().updateUpdateStateFaild(listBeanList.get(i).calendId, -1);
                                                    }
                                                }
                                                sharedPrefUtil.putString(getApplication(), ShareFile.USERFILE, ShareFile.DOWNREPTIME,
                                                        listBeanList.get(i).downTime.replace("T", " "));
                                            }
                                        }
                                    }
                                }
                            }
                            upLoadState();
                            uploadCalendernote();
                        }
                    }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    upLoadState();
                    uploadCalendernote();
                }
            }) {
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("json", schjson);
                    Log.e("TAG", schjson);
                    return map;
                }
            };
            request.setTag("uploadCalender");
            request.setRetryPolicy(new DefaultRetryPolicy(10000, 1, 1.0f));
            App.getHttpQueues().add(request);
        } catch (Exception e) {
            e.printStackTrace();
            uploadCalendernote();
        }
    }

    private void uploadCalendernote() {
        list = App.getDBcApplication().getCalenderNoteDetailData(userid, maxTitleId, false);
        if (list.size() > 0) {
            updateList();
            deleteEmpty();
        }
        JSONObject listjsonObject = new JSONObject();
        JSONArray listjsonArray = new JSONArray();
        try {
            for (CalenderNoteBean.PageBean.ItemsBean bean : list) {
                JSONObject js = new JSONObject();
                js.put("id", bean.id);
                js.put("titleId", bean.titleId);
                js.put("uid", bean.uid);
                js.put("titles", bean.titles);
                js.put("imgPath", bean.imgPath);
                js.put("imgUrl", bean.imgUrl);
                js.put("shareUrl", bean.shareUrl);
                js.put("contents", bean.contents);
                js.put("nums", bean.nums);
                js.put("style", bean.style);
                js.put("endstate", bean.endstate);
                js.put("lType", bean.ltype);
                js.put("orderId", bean.orderId);
                js.put("createTime", bean.createTime);
                js.put("changeTime", bean.changeTime);
                js.put("cpath", bean.cpath);
                js.put("curl", bean.curl);
                js.put("sdesc", bean.sdesc);
                js.put("localIds", bean.localIds);
                js.put("remark", bean.remark);
                js.put("remark1", bean.remark1);
                js.put("remark2", bean.remark2);
                js.put("remark3", bean.remark3);
                js.put("remark4", bean.remark4);
                js.put("remark4", bean.remark5);
                js.put("remark4", bean.remark6);
                js.put("updateState", bean.id < 0 ? 1 : App.getDBcApplication().getCalenderNoteDetailState(bean.titleId, userid, bean.id));
                listjsonArray.put(js);
            }
            if (list.size() > 0) {
                listjsonObject.put("timetable", listjsonArray);
            }


            HttpUtils httpUtils = new HttpUtils(10000);
            RequestParams params = new RequestParams();
            params.addBodyParameter("data", listjsonObject == null ? "" : listjsonObject.toString());
            httpUtils.send(HttpMethod.POST, URLConstants.日程清单同步数据, params,
                    new RequestCallBack<String>() {

                        @Override
                        public void onFailure(HttpException e, String msg) {
                        }

                        @Override
                        public void onSuccess(ResponseInfo<String> responseInfo) {
                            if (!TextUtils.isEmpty(responseInfo.result)) {
                                Gson gson = new Gson();
                                CalenderNoteSynBean bean = gson.fromJson(responseInfo.result, CalenderNoteSynBean.class);
                                if (bean.status == 0) {
                                    List<CalenderNoteSynBean.ListBean> listBeanList = bean.list;


                                    for (CalenderNoteSynBean.ListBean listBean : listBeanList) {
                                        if (listBean.dataState == 1) {//新增
                                            if (listBean.state == 0) {//成功
                                                //修改id和状态值
                                                App.getDBcApplication().updateCalenderNoteDetailId(listBean.id, listBean.calendId, userid);
                                                for (int i = 0; i < list.size(); i++) {
                                                    CalenderNoteBean.PageBean.ItemsBean beanitem = list.get(i);
                                                    if (listBean.id == beanitem.id) {
                                                        list.get(i).setId(listBean.calendId);
                                                    }
                                                }
                                                App.getDBcApplication().updateCalenderNoteDetailState("", listBean.calendId, userid, 0, true);
                                            } else if (listBean.state == 1) {//失败  可以不操作,但是避免意外
                                                //更改状态为1
                                                App.getDBcApplication().updateCalenderNoteDetailState("", listBean.id, userid, 1, true);
                                            } else if (listBean.state == 2) { //异常
                                                App.getDBcApplication().updateCalenderNoteDetailState("", listBean.id, userid, -1, true);
                                            }
                                        } else if (listBean.dataState == 2) {//修改
                                            if (listBean.state == 0) {//成功
                                                //修改该id状态值
                                                App.getDBcApplication().updateCalenderNoteDetailState("", listBean.id, userid, 0, true);
                                            } else if (listBean.state == 1) {//失败
                                                //更改状态为2
                                                App.getDBcApplication().updateCalenderNoteDetailState("", listBean.id, userid, 2, true);
                                            } else if (listBean.state == 2) { //异常
                                                App.getDBcApplication().updateCalenderNoteDetailState("", listBean.id, userid, -1, true);
                                            }
                                        } else if (listBean.dataState == 3) {//删除
                                            if (listBean.state == 0) {//成功
                                                //删除该id的清单
                                                App.getDBcApplication().deleteCalenderNoteTitledetailData(listBean.id, userid, true);
                                            } else if (listBean.state == 1) {//失败
                                                //更改状态为3
                                                App.getDBcApplication().updateCalenderNoteDetailState("", listBean.id, userid, 3, true);
                                            } else if (listBean.state == 2) { //异常
                                                App.getDBcApplication().updateCalenderNoteDetailState("", listBean.id, userid, -1, true);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    class newOneCallBack implements PlatformActionListener {

        @Override
        public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
        }

        @Override
        public void onError(Platform platform, int i, Throwable throwable) {
        }

        @Override
        public void onCancel(Platform platform, int i) {
        }
    }


    private void sendMessageDialog(String content) {
        Dialog dialog = new Dialog(context, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        params.alpha = 0.92f;
        params.y = 150;
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(context);
        View more_pop_menu = fac.inflate(R.layout.dialog_sendmessagedialog,
                null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = getWindowManager().getDefaultDisplay()
                .getWidth() - 30;
        dialog.show();
        new SendMessageDetailOnClick(dialog, more_pop_menu, content);
    }

    int displaytime, postpone;

    class SendMessageDetailOnClick implements OnClickListener {

        private View mainView;
        private Dialog dialog;
        private String content;
        private String alamsound;
        private String alamsoundDesc;
        private LinearLayout detail_edit;
        private LinearLayout detail_close;
        private Button suresend_bt;
        private TextView time_date;
        private TextView year_date;
        private TextView shunyan_tv;
        private TextView content_tv;
        private TextView timebefore_tv;
        private TextView week_date;
        Map<Object, Object> map;
        String today, tomorrow;
        Calendar calendar = Calendar.getInstance();

        String date;

        public SendMessageDetailOnClick(Dialog dialog, View view, String content) {
            this.mainView = view;
            this.dialog = dialog;
            this.content = content;
            initview();
            initdata();
        }

        public void initview() {
            detail_edit = (LinearLayout) mainView
                    .findViewById(R.id.detail_edit);
            detail_edit.setOnClickListener(this);
            detail_close = (LinearLayout) mainView
                    .findViewById(R.id.detail_close);
            detail_close.setOnClickListener(this);
            suresend_bt = (Button) mainView.findViewById(R.id.suresend_bt);
            suresend_bt.setOnClickListener(this);
            time_date = (TextView) mainView.findViewById(R.id.time_date);
            year_date = (TextView) mainView.findViewById(R.id.year_date);
            shunyan_tv = (TextView) mainView.findViewById(R.id.shunyan_tv);
            content_tv = (TextView) mainView.findViewById(R.id.content_tv);
            timebefore_tv = (TextView) mainView
                    .findViewById(R.id.timebefore_tv);
            week_date = (TextView) mainView.findViewById(R.id.week_date);
            map = ReadTextContentXml.ReadWeiXinXml.yuyinSb(context, content);
        }

        public void initdata() {
            if (map != null) {

                alamsound = (String) map.get("ringDesc");
                alamsoundDesc = (String) map.get("ringVal");
                content = (String) map.get("value");

                calendar.setTime(new Date());
                today = DateUtil.formatDate(calendar.getTime());
                calendar.set(Calendar.DAY_OF_MONTH,
                        calendar.get(Calendar.DAY_OF_MONTH) + 1);
                tomorrow = DateUtil.formatDate(calendar.getTime());

                content_tv.setText(content);
                date = DateUtil.formatDate(DateUtil.parseDate((String) map.get("date")));
                if (today.equals(date)) {
                    year_date.setText(date);
                } else if (tomorrow.equals(date)) {
                    year_date.setText("明天");
                } else {
                    year_date.setText(date);
                }
                String timestr = "";
                if (displaytime == 0) {
                    time_date.setText("全天");
                    timestr = sharedPrefUtil.getString(context,
                            ShareFile.USERFILE, ShareFile.ALLTIME, "08:30");
                } else {
                    time_date.setText((String) map.get("time"));
                    timestr = time_date.getText().toString();
                }
                week_date.setText(CharacterUtil.getWeekOfDate(context,
                        DateUtil.parseDate(date)));
                String colorState = ""
                        + context.getResources().getColor(
                        R.color.mingtian_color);
                String sequence = "<font color='" + colorState + "'>"
                        + context.getString(R.string.adapter_shun) + "</font>";

                shunyan_tv.setBackgroundResource(R.drawable.tv_kuang_aftertime);
                shunyan_tv.setText(Html.fromHtml(sequence));
                if (0 == postpone) {
                    shunyan_tv.setVisibility(View.GONE);
                } else {
                    shunyan_tv.setVisibility(View.VISIBLE);
                }
                Date dateStr = DateUtil.parseDateTime(date + " " + timestr);
                Date dateToday = DateUtil.parseDateTime(DateUtil
                        .formatDateTime(new Date()));
                long betweem = (long) (dateStr.getTime() - dateToday.getTime()) / 1000;
                long day = betweem / (24 * 3600);
                long hour = betweem % (24 * 3600) / 3600;
                long min = betweem % 3600 / 60;

                if (today.equals(date)) {// 今天
                    if (displaytime == 0 && postpone == 1) {
                        timebefore_tv.setText("今天");
                    } else {
                        if (DateUtil.parseDate(DateUtil.formatDate(new Date()))
                                .after(DateUtil.parseDate(DateUtil
                                        .formatDate(dateStr)))) {
                            if (Math.abs(hour) >= 1) {
                                timebefore_tv.setText(Math.abs(hour) + "小时前");
                            } else {
                                timebefore_tv.setText(Math.abs(min) + "分钟前");
                            }
                        } else {
                            if (Math.abs(hour) >= 1) {
                                timebefore_tv.setText(Math.abs(hour) + "小时后");
                            } else {
                                timebefore_tv.setText(Math.abs(min) + "分钟后");
                            }
                        }
                    }
                } else if (tomorrow.equals(date)) {// 明天
                    if (Math.abs(day) >= 1) {
                        timebefore_tv.setText(Math.abs(day) + "天后");
                    } else {
                        timebefore_tv.setText(Math.abs(hour) + "小时后");
                    }
                } else {
                    timebefore_tv.setText(Math.abs(day) + 1 + "天后");
                }
            }
        }

        @Override
        public void onClick(View v) {
            Intent intent = null;
            switch (v.getId()) {
                case R.id.detail_edit:
                    if (!"".equals(content_tv.getText().toString().trim())) {
                        intent = new Intent(context, EditSchActivity.class);
                        intent.putExtra("content", content);
                        intent.putExtra("displaytime", displaytime + "");
                        intent.putExtra("postpone", postpone + "");
                        intent.putExtra("ringdesc", alamsoundDesc);
                        intent.putExtra("ringcode", alamsound);
                        intent.putExtra("date", date);
                        intent.putExtra("time", (String) map.get("time"));
                        startActivityForResult(intent, 100);
                        dialog.dismiss();
                    } else {
                        Toast.makeText(context, "内容不能为空..", Toast.LENGTH_SHORT).show();
                        return;
                    }
                    break;
                case R.id.detail_close:
                    dialog.dismiss();
                    break;
                case R.id.suresend_bt:
                    try {
                        App.getDBcApplication().insertScheduleData(content, date,
                                (String) map.get("time"), 1,
                                0, displaytime, postpone, 0,
                                0, 0, DateUtil.formatDateTime(new Date()), "", 0,
                                "", "", 0, "", DateUtil.formatDateTime(new Date()),
                                1, 0, 0, alamsoundDesc, alamsound, "", 0, 0, 0, "",
                                "", 0, 0, 0, 0, schRemark1, "0", "0");
                        QueryAlarmData.writeAlarm(context.getApplicationContext());
                        Intent intentappwidget = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                        Bundle extras = new Bundle();
                        intentappwidget.putExtras(extras);
                        sendBroadcast(intentappwidget);
                        Intent intent1 = new Intent(Const.SHUAXINDATA);
                        intent1.putExtra("data", "success");
                        intent1.putExtra("index", 1);
                        intent1.putExtra("what", 2);
                        context.sendBroadcast(intent1);

                        Toast.makeText(context, "添加成功", Toast.LENGTH_SHORT).show();
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                    }
                    dialog.dismiss();
                    break;
                default:
                    break;
            }
        }

    }

    private void dialogMorningTimeOnClick(TextView time_tv) {
        final BaseDialog dialog = new BaseDialog(context, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        android.view.WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
//        params.alpha = 0.92f;
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(context);
        View more_pop_menu = fac.inflate(R.layout.dialog_gundong_time, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = getWindowManager().getDefaultDisplay().getWidth();
        dialog.show();
        dialog.setCallBack(new BaseDialog.CallBack() {
            @Override
            public void onTouchOutside() {
                sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.CLOCKORDER, "0");
                dialog.dismiss();
            }
        });
        new TimeOnClick(dialog, more_pop_menu, time_tv);
    }

    class TimeOnClick {

        private View view;
        private Dialog dialog;
        // private PickerView hour_pv;
        // private PickerView minute_pv;
        CycleWheelView hour_cy;
        CycleWheelView min_cy;
        String hour;
        String minute;
        private String timeSet = "";
        private TextView time_tv;

        Map<String, String> mMap;
        ToggleButton toggleButton;

        @SuppressLint("NewApi")
        public TimeOnClick(Dialog dialog, View view, TextView time_tv) {
            this.dialog = dialog;
            this.view = view;
            this.time_tv = time_tv;
            timeSet = schTime;
            initview();
            initdata();
        }

        private void initview() {
            hour_cy = (CycleWheelView) view.findViewById(R.id.hour_cy);
            min_cy = (CycleWheelView) view.findViewById(R.id.min_cy);

//            view.findViewById(R.id.bp).setOnClickListener(new OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    dialog.dismiss();
//                    initDiaLog(time_tv);
//                }
//            });

            toggleButton = (ToggleButton) view.findViewById(R.id.toggle);
            if (schDisplayTime == 0) {
                toggleButton.setChecked(true);
            } else {
                toggleButton.setChecked(false);
            }
            toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView,
                                             boolean isChecked) {
                    if (isChecked) {
                        o_ll.setVisibility(View.GONE);
                        calender_time.setText("全天");
                        schDisplayTime = 0;
                        isAlarm = 0;
                    } else {
                        o_ll.setVisibility(View.VISIBLE);
                        schDisplayTime = 1;
                        calender_time.setText(timeSet);
                        isAlarm = copyisAlarm;
                    }
                }
            });
        }

        private void initdata() {
            int curHours = Integer.parseInt(timeSet.split(":")[0]);
            int curMinutes = Integer.parseInt(timeSet.split(":")[1]);
            hour = curHours + "";
            minute = curMinutes + "";
            int currentHoursIndex = 0;
            int currentMinutesIndex = 0;
            List<String> hours = new ArrayList<String>();
            List<String> minutes = new ArrayList<String>();
            for (int i = 0; i < 24; i++) {
                hours.add(i < 10 ? "0" + i : "" + i);

            }
            for (int i = 0; i < 60; i++) {
                minutes.add(i < 10 ? "0" + i : "" + i);
            }
            for (int i = 0; i < hours.size(); i++) {
                if (curHours == Integer.parseInt(hours.get(i))) {
                    currentHoursIndex = i;
                }
            }
            for (int i = 0; i < minutes.size(); i++) {
                if (curMinutes == Integer.parseInt(minutes.get(i))) {
                    currentMinutesIndex = i;
                }
            }
            hour_cy.setLabels(hours);
            try {
                hour_cy.setWheelSize(5);
            } catch (CycleWheelView.CycleWheelViewException e) {
                e.printStackTrace();
            }
            hour_cy.setCycleEnable(true);
            hour_cy.setSelection(currentHoursIndex);
            hour_cy.setAlphaGradual(0.6f);
            hour_cy.setDivider(getResources().getColor(R.color.gongkai_txt), 1);
            hour_cy.setSolid(Color.WHITE, Color.WHITE);
            hour_cy.setLabelColor(getResources().getColor(R.color.gongkai_txt));
            hour_cy.setLabelSelectColor(Color.BLACK);
            hour_cy.setOnWheelItemSelectedListener(new CycleWheelView.WheelItemSelectedListener() {
                @Override
                public void onItemSelected(int position, String label) {
                    hour = Integer.parseInt(label) < 10 ? "0"
                            + Integer.parseInt(label) : label;
                    minute = Integer.parseInt(minute) < 10 ? "0"
                            + Integer.parseInt(minute) : minute;

                    if (!timeSet.equals(hour + ":" + minute)) {
                        toggleButton.setChecked(false);
                    }
                    schTime = timeSet = hour + ":" + minute;
                    if (toggleButton.isChecked() == false) {
                        calender_time.setText(timeSet);
                        isAlarm = copyisAlarm;
                        schDisplayTime = 1;
                        o_ll.setVisibility(View.VISIBLE);
                    }
                }
            });

            min_cy.setLabels(minutes);
            try {
                min_cy.setWheelSize(5);
            } catch (CycleWheelView.CycleWheelViewException e) {
                e.printStackTrace();
            }
            min_cy.setCycleEnable(true);
            min_cy.setSelection(currentMinutesIndex);
            min_cy.setAlphaGradual(0.6f);
            min_cy.setDivider(getResources().getColor(R.color.gongkai_txt), 1);
            min_cy.setSolid(Color.WHITE, Color.WHITE);
            min_cy.setLabelColor(getResources().getColor(R.color.gongkai_txt));
            min_cy.setLabelSelectColor(Color.BLACK);
            min_cy.setOnWheelItemSelectedListener(new CycleWheelView.WheelItemSelectedListener() {
                @Override
                public void onItemSelected(int position, String label) {
                    hour = Integer.parseInt(hour) < 10 ? "0"
                            + Integer.parseInt(hour) : hour;
                    minute = Integer.parseInt(label) < 10 ? "0"
                            + Integer.parseInt(label) : label;
                    if (!timeSet.equals(hour + ":" + minute)) {
                        toggleButton.setChecked(false);
                    }
                    schTime = timeSet = hour + ":" + minute;
                    if (toggleButton.isChecked() == false) {
                        calender_time.setText(timeSet);
                        isAlarm = copyisAlarm;
                        schDisplayTime = 1;
                        o_ll.setVisibility(View.VISIBLE);
                    }
                }
            });
        }
    }

    String beforeType = "";

    private void initDiaLog(TextView time_tv) {
        final BaseDialog dialog = new BaseDialog(context, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
//        params.alpha = 0.92f;
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(context);
        View more_pop_menu = fac.inflate(R.layout.dialog_calender_time, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = getWindowManager().getDefaultDisplay().getWidth();
        dialog.show();
        dialog.setCallBack(new BaseDialog.CallBack() {
            @Override
            public void onTouchOutside() {
                sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.CLOCKORDER, "1");
                dialog.dismiss();
            }
        });

        new MyClick(dialog, more_pop_menu, time_tv);
    }

    private Animation animationTranslate;
    private RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(0, 0);

    // 移动的动画效果
    /*
     * TranslateAnimation(float fromXDelta, float toXDelta, float
     * fromYDelta,float toYDelta)
     *
     * float fromXDelta:这个参数表示动画开始的点离当前View X坐标上的差值；
     *
     * float toXDelta, 这个参数表示动画结束的点离当前View X坐标上的差值；
     *
     * float fromYDelta, 这个参数表示动画开始的点离当前View Y坐标上的差值；
     *
     * float toYDelta)这个参数表示动画开始的点离当前View Y坐标上的差值；
     */
    protected Animation animTranslate(float toX, float toY, final int x1,
                                      final int y1, final TextView textView, long durationMillis) {
        animationTranslate = new TranslateAnimation(toX, toX, toY, toY);
        animationTranslate.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                params = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT,
                        RelativeLayout.LayoutParams.WRAP_CONTENT);
                params.setMargins(x1, y1, 0, 0);
                textView.setLayoutParams(params);
                textView.setPadding(12, 7, 12, 7);
                textView.clearAnimation();
            }
        });
        animationTranslate.setDuration(durationMillis);
        return animationTranslate;
    }

    class MyClick implements OnClickListener {

        private Dialog dialog;
        private RelativeLayout rela_hour;
        private RelativeLayout rela_minutes;
        private int hours = 12;
        private int minutes = 0;
        private int width;
        private int centerX;
        private int centerY;
        private Calendar calendar;
        private int lastMinutes;
        private TextView dialog_tv_state, dialog_tv_state1;
        private int grState;// 结果为0是上午 结果为1是下午
        private String chooseHour;
        private String chooseMinute;

        private TextView tv_clock_state;
        private LinearLayout ll_clock, state_ll;
        private TextView tv_clock_time;
        private TextView tv_clock_beforetime;
        private TextView time_tv, tv_gt;

        private RelativeLayout date_re;
        String time;

        private MyClick(Dialog dialog, View more_pop_menu, TextView time_tvs) {
            this.dialog = dialog;
            this.time_tv = time_tvs;
            time = schTime;
            calendar = Calendar.getInstance();
            // if (isNeedPush) {
            String[] times;

            if ("全天".equals(time)) {
                times = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.ALLTIME, "08:58").split(":");
            } else {
                times = time.split(":");
            }
            calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(times[0]));
            calendar.set(Calendar.MINUTE, Integer.parseInt(times[1]));
            // }
            rela_hour = (RelativeLayout) more_pop_menu
                    .findViewById(R.id.rela_hour);
            rela_minutes = (RelativeLayout) more_pop_menu
                    .findViewById(R.id.rela_minutes);

            dialog_tv_state = (TextView) more_pop_menu
                    .findViewById(R.id.dialog_tv_state);
            date_re = (RelativeLayout) more_pop_menu
                    .findViewById(R.id.date_re);
            dialog_tv_state1 = (TextView) more_pop_menu
                    .findViewById(R.id.dialog_tv_state1);
            state_ll = (LinearLayout) more_pop_menu
                    .findViewById(R.id.state_ll);
            state_ll.setOnClickListener(this);
            tv_clock_state = (TextView) more_pop_menu
                    .findViewById(R.id.tv_clock_state);
            tv_clock_state.setOnClickListener(this);

            tv_gt = (TextView) more_pop_menu.findViewById(R.id.tv_gt);
            tv_gt.setOnClickListener(this);
            ll_clock = (LinearLayout) more_pop_menu.findViewById(R.id.ll_clock);
            ll_clock.setOnClickListener(this);

            tv_clock_time = (TextView) more_pop_menu.findViewById(R.id.tv_clock_time);
            tv_clock_beforetime = (TextView) more_pop_menu.findViewById(R.id.tv_clock_beforetime);

            width = getWindowManager().getDefaultDisplay().getWidth();
            int haf = Utils.dipTopx(context, 20);
            centerX = width / 2 - Utils.dipTopx(context, 16);
            centerY = width / 2 - Utils.dipTopx(context, 16) - haf;

            initclockValue();
            initHour();
            initMinutes();

            grState = calendar.get(Calendar.AM_PM);
//            if (grState == 0) {// 结果为0是上午 结果为1是下午
//                dialog_tv_state.setText("上午");
//            } else {
//                dialog_tv_state.setText("下午");
//            }
            if (grState == 1) {// 上午
                dialog_tv_state1.setTextColor(Color.parseColor("#08f0ff"));
                dialog_tv_state1.setTextSize(30);
                dialog_tv_state.setTextColor(Color.parseColor("#aaaaaa"));
                dialog_tv_state.setTextSize(14);
                grState = 1;
                calendar.set(Calendar.AM_PM, grState);
            } else if (grState == 0) {// 下午
                dialog_tv_state.setTextColor(Color.parseColor("#08f0ff"));
                dialog_tv_state.setTextSize(30);
                dialog_tv_state1.setTextColor(Color.parseColor("#aaaaaa"));
                dialog_tv_state1.setTextSize(14);
                grState = 0;
                calendar.set(Calendar.AM_PM, grState);
            }
        }

        private void initclockValue() {
            tv_clock_time.setText(time);
            if (time.split(":")[0].substring(0, 1).equals("0")) {
                if (Integer.valueOf(time.split(":")[0].substring(1, time.split(":")[0].length())) >= 0 &&
                        Integer.valueOf(time.split(":")[0].substring(1, time.split(":")[0].length())) <= 6) {
                    tv_clock_time.setText("凌晨 " + time);
                }
            }
        }

        private void initHour() {
            int hour = calendar.get(Calendar.HOUR);
            if (hour == 0) {
                hour = 12;
            }
            int hourRadius = Utils.dipTopx(context, 90); // 设置圆半径
            for (int i = 12; i >= 1; i--) {
                int dy = (int) (hourRadius * Math.cos((Math.PI / 6.0) * i));
                int dx = (int) (hourRadius * Math.sin((Math.PI / 6.0) * i));

                int x1 = centerX + dx;
                int y1 = centerY - dy;

                String text = hours < 10 ? "0" + hours : "" + hours;

                TextView textView = new TextView(context);
                textView.setText(text);
                textView.setTextColor(Color.WHITE);
                textView.setTextSize(18.0f);
                textView.setGravity(Gravity.CENTER);
                textView.setLayoutParams(new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT));
                textView.setTag(i);
                textView.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        chooseHour = v.getTag().toString();
                        chageHour(Integer.parseInt(chooseHour));
                        calendar.set(Calendar.HOUR,
                                Integer.parseInt(chooseHour));
                        calendar.set(Calendar.MINUTE,
                                Integer.parseInt(chooseMinute));
                        if (grState == 0) {// 上午
                            calendar.set(Calendar.AM_PM, 0);
                        } else if (grState == 1) {// 下午
                            calendar.set(Calendar.AM_PM, 1);
                        }
                        String calendarHour = calendar
                                .get(Calendar.HOUR_OF_DAY) < 10 ? "0"
                                + calendar.get(Calendar.HOUR_OF_DAY) : ""
                                + calendar.get(Calendar.HOUR_OF_DAY);
                        String calendarMinute = calendar.get(Calendar.MINUTE) < 10 ? "0"
                                + calendar.get(Calendar.MINUTE)
                                : "" + calendar.get(Calendar.MINUTE);
                        time_tv.setText(calendarHour + ":" + calendarMinute);
                        schDisplayTime = 1;
                        o_ll.setVisibility(View.VISIBLE);
                        isAlarm = copyisAlarm;
                        schTime = calendarHour + ":" + calendarMinute;
                        tv_clock_time.setText(((0 <= calendar
                                .get(Calendar.HOUR_OF_DAY) && calendar
                                .get(Calendar.HOUR_OF_DAY) <= 6) ? "凌晨" : "") + calendarHour + ":" + calendarMinute);
                    }
                });

                if (hour == i) {
                    if (time.equals("全天")) {
                        textView.setBackgroundDrawable(null);
                    } else {
                        chooseHour = text;
                        textView.setTextColor(Color.WHITE);
                        textView.setBackgroundResource(R.mipmap.icon_shuzi1);
                    }
                } else {
                    textView.setBackgroundDrawable(null);
                }

                rela_hour.addView(textView);

                textView.setAnimation(animTranslate(centerX, centerY, x1, y1, textView, 200));

                hours--;
            }
        }

        private void initMinutes() {
            int minute = calendar.get(Calendar.MINUTE);
            int result = minute % 5;
            if (result != 0) {
                int division = minute / 5;
                minute = division * 5;
            }
            int minutesRadius = Utils.dipTopx(context, 140); // 设置圆半径
            for (int i = 0; i < 12; i++) {
                int dy = (int) (minutesRadius * Math.cos((Math.PI / 6.0) * i));
                int dx = (int) (minutesRadius * Math.sin((Math.PI / 6.0) * i));

                int x1 = centerX + dx;
                int y1 = centerY - dy;

                String text = minutes * 5 < 10 ? "0" + minutes * 5 : "" + minutes * 5;

                TextView textView = new TextView(context);
                textView.setText(text);
                textView.setTextColor(Color.WHITE);
                textView.setTextSize(18.0f);
                textView.setGravity(Gravity.CENTER);
                textView.setLayoutParams(new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT));
                textView.setTag(text);
                textView.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        chooseMinute = v.getTag().toString();
                        chageMinutes(Integer.parseInt(chooseMinute) / 5);
                        lastMinutes = Integer.parseInt(chooseMinute) / 5;
                        calendar.set(Calendar.HOUR,
                                Integer.parseInt(chooseHour));
                        calendar.set(Calendar.MINUTE,
                                Integer.parseInt(chooseMinute));
                        if (grState == 0) {// 上午
                            calendar.set(Calendar.AM_PM, 0);
                        } else if (grState == 1) {// 下午
                            calendar.set(Calendar.AM_PM, 1);
                        }
                        String calendarHour = calendar
                                .get(Calendar.HOUR_OF_DAY) < 10 ? "0"
                                + calendar.get(Calendar.HOUR_OF_DAY) : ""
                                + calendar.get(Calendar.HOUR_OF_DAY);
                        String calendarMinute = calendar.get(Calendar.MINUTE) < 10 ? "0"
                                + calendar.get(Calendar.MINUTE)
                                : "" + calendar.get(Calendar.MINUTE);
                        time_tv.setText(calendarHour + ":" + calendarMinute);
                        schDisplayTime = 1;
                        o_ll.setVisibility(View.VISIBLE);
                        isAlarm = copyisAlarm;
                        schTime = calendarHour + ":" + calendarMinute;
                        tv_clock_time.setText(((0 <= calendar
                                .get(Calendar.HOUR_OF_DAY) && calendar
                                .get(Calendar.HOUR_OF_DAY) <= 6) ? "凌晨" : "") + calendarHour + ":" + calendarMinute);
                    }
                });
                if (minute == Integer.parseInt(text)) {
                    if (time.equals("全天")) {
                        textView.setBackgroundDrawable(null);
                    } else {
                        lastMinutes = i;
                        chooseMinute = text;
                        textView.setTextColor(Color.WHITE);
                        textView.setBackgroundResource(R.mipmap.icon_shuzi2);
                    }
                } else {
                    textView.setBackgroundDrawable(null);
                }
                rela_minutes.addView(textView);
                textView.setAnimation(animTranslate(centerX, centerY, x1, y1, textView, 200));

                minutes++;
            }
        }

        private void chageHour(int hours) {
            for (int i = rela_hour.getChildCount() - 1; i >= 0; i--) {
                TextView tv_hour = (TextView) rela_hour.getChildAt(i);
                if (hours == Integer.parseInt(tv_hour.getTag().toString())) {
                    tv_hour.setBackgroundResource(R.mipmap.icon_shuzi1);
                } else {
                    tv_hour.setBackgroundDrawable(null);
                }
            }
        }

        private void chageMinutes(int minutes) {
            TextView textView = (TextView) rela_minutes.getChildAt(lastMinutes);
            textView.setBackgroundDrawable(null);
            TextView tv_minutes = (TextView) rela_minutes.getChildAt(minutes);
            tv_minutes.setBackgroundResource(R.mipmap.icon_shuzi2);
        }


        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.tv_gt:
                    dialogMorningTimeOnClick(time_tv);
                    dialog.dismiss();
                    break;
                case R.id.state_ll:
                    calendar.set(Calendar.HOUR, Integer.parseInt(chooseHour));
                    calendar.set(Calendar.MINUTE, Integer.parseInt(chooseMinute));
                    if (grState == 0) {// 上午
                        dialog_tv_state1.setTextColor(Color.parseColor("#08f0ff"));
                        dialog_tv_state1.setTextSize(30);
                        dialog_tv_state.setTextColor(Color.parseColor("#aaaaaa"));
                        dialog_tv_state.setTextSize(14);
                        grState = 1;
                        calendar.set(Calendar.AM_PM, grState);
                    } else if (grState == 1) {// 下午
                        dialog_tv_state.setTextColor(Color.parseColor("#08f0ff"));
                        dialog_tv_state.setTextSize(30);
                        dialog_tv_state1.setTextColor(Color.parseColor("#aaaaaa"));
                        dialog_tv_state1.setTextSize(14);
                        grState = 0;
                        calendar.set(Calendar.AM_PM, grState);
                    }
//                    dialog_tv_state.startAnimation(AnimationUtils.loadAnimation(context, R.anim.scale_in));
                    String calendarHour = calendar.get(Calendar.HOUR_OF_DAY) < 10 ? "0"
                            + calendar.get(Calendar.HOUR_OF_DAY)
                            : "" + calendar.get(Calendar.HOUR_OF_DAY);
                    String calendarMinute = calendar.get(Calendar.MINUTE) < 10 ? "0"
                            + calendar.get(Calendar.MINUTE)
                            : "" + calendar.get(Calendar.MINUTE);
                    time_tv.setText(calendarHour + ":" + calendarMinute);
                    tv_clock_time.setText(((0 <= calendar.get(Calendar.HOUR_OF_DAY) && calendar
                            .get(Calendar.HOUR_OF_DAY) <= 6) ? "凌晨" : "") + calendarHour + ":" + calendarMinute);
                    schTime = calendarHour + ":" + calendarMinute;
                    schDisplayTime = 1;
                    o_ll.setVisibility(View.VISIBLE);
                    isAlarm = copyisAlarm;
//                    dialog.dismiss();
                    break;

                case R.id.tv_clock_state:
                    // isNeedPush = false;
                    time_tv.setText("全天");
                    o_ll.setVisibility(View.GONE);
                    schDisplayTime = 0;
                    isAlarm = 0;
                    // tv_beforetime.setText("");
//                    dialog.dismiss();
                    break;

                case R.id.ll_clock:
//                    if (date_re.getVisibility() == View.VISIBLE){
//                        date_re.setVisibility(View.GONE);
//                        time_ll.setVisibility(View.VISIBLE);
//                    }else {
//                        date_re.setVisibility(View.VISIBLE);
//                        time_ll.setVisibility(View.GONE);
//                    }
                    break;

                default:
                    dialog.dismiss();

                    break;
            }
        }

    }

    int[] solartime = new int[25];
    boolean isLeap = false;
    boolean isRed = false;
    ArrayList<HashMap<String, String>> data;
    String today;
    int temp_day;
    int temp_month;
    int temp_year;

    int to_day;
    int to_month;
    int to_year;
    int standard_day;
    int standard_month;
    int standard_year;
    String holiday = "";
    String curDate = "";

    int sourse;//
    String dateTime = "";// 日期
    private TextView title;

    MyLinearLayout dataLinear;
    Handler handlerrili;
    LinearLayout.LayoutParams mLayoutParamss = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);

    private void initRiliDiaLog(final boolean isCopy, final String meesage) {
        final Dialog dialog = new Dialog(context, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(context);
        View more_pop_menu = fac.inflate(R.layout.dialog_calender_rili, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = getWindowManager().getDefaultDisplay().getWidth();
        dialog.show();

        curDate = dateTime;

        dataLinear = (MyLinearLayout) more_pop_menu.findViewById(R.id.datalinear);
        title = (TextView) more_pop_menu.findViewById(R.id.title);
        dataLinear.setBackgroundColor(Color.WHITE);
        more_pop_menu.findViewById(R.id.today).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                curDate = DateUtil.formatDate(new Date());// new Date()为获取当前系统时间
                GenData(true, curDate);
                GenView();
            }
        });
        more_pop_menu.findViewById(R.id.lastmonth).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (standard_month == 1) {
                    standard_month = 12;
                    standard_year--;
                } else {
                    standard_month--;
                }
                GenData(false, curDate);
                GenView();
                title.setText(standard_year + "年" + standard_month + "月");
                dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.right_in));

            }
        });
        more_pop_menu.findViewById(R.id.nextmonth).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (standard_month == 12) {
                    standard_month = 1;
                    standard_year++;
                } else {
                    standard_month++;
                }
                GenData(false, curDate);
                GenView();
                title.setText(standard_year + "年" + standard_month + "月");
                dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.left_in));

            }
        });
        handlerrili = new Handler() {
            public void handleMessage(Message msg) {
                if (msg == null) {
                    return;
                }
                switch (msg.what) {
                    case 0:
                        if (standard_month == 1) {
                            standard_month = 12;
                            standard_year--;
                        } else {
                            standard_month--;
                        }
                        GenData(false, curDate);
                        GenView();
                        title.setText(standard_year + "年" + standard_month + "月");
                        dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.right_in));
                        break;

                    case 1:
                        if (standard_month == 12) {
                            standard_month = 1;
                            standard_year++;
                        } else {
                            standard_month++;
                        }
                        GenData(false, curDate);
                        GenView();
                        title.setText(standard_year + "年" + standard_month + "月");
                        dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.left_in));
                        break;

                    case 2:
                        standard_year--;
                        GenData(false, curDate);
                        GenView();
                        title.setText(standard_year + "年" + standard_month + "月");
                        dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.down_in));
                        break;

                    case 3:
                        standard_year++;
                        GenData(false, curDate);
                        GenView();
                        title.setText(standard_year + "年" + standard_month + "月");
                        dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.up_in));
                        break;

                    case 9:
                        dialog.dismiss();
                        if (isCopy) {
                            if (meesage.isEmpty()) {
                                Toast.makeText(context, "已复制", Toast.LENGTH_SHORT).show();
                                App.getDBcApplication().copyCalnederNoteData(userid, schID, maxTitleId, msg.obj.toString());
                                Toast.makeText(context, "已复制", Toast.LENGTH_SHORT).show();
                            } else {
                                App.getDBcApplication().insertScheduleData(meesage, msg.obj + "",
                                        DateUtil.nowTimes(), 1,
                                        0, 1, 0, 0,
                                        0, 0, DateUtil.formatDateTime(new Date()), "", 0,
                                        "", "", 0, "", DateUtil.formatDateTime(new Date()),
                                        1, 0, 0, "完成任务", "g_88", "", 0, 0, 0, "",
                                        "", 0, 0, 0, 0, schRemark1, "0", "0");
                                Toast.makeText(context, "已加入", Toast.LENGTH_SHORT).show();
                            }

                            QueryAlarmData.writeAlarm(context.getApplicationContext());
                            Intent intentappwidget = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                            Bundle extras = new Bundle();
                            intentappwidget.putExtras(extras);
                            sendBroadcast(intentappwidget);
                            Intent intent1 = new Intent(Const.SHUAXINDATA);
                            intent1.putExtra("data", "success");
                            intent1.putExtra("index", 1);
                            intent1.putExtra("what", 2);
                            context.sendBroadcast(intent1);

                        } else {
                            calender_date.setText(msg.obj.toString());
                            calender_week.setText(Week(msg.obj.toString()));
                        }

                        break;

                    case 11:
                        break;

                    case 12:
                        break;
                }
            }
        };
        dataLinear.setHandler(handlerrili);


        new LoadDataAsyncTask().execute();


    }

    public String nums() {
        int tick1 = 0;
        int tick2 = 0;
        for (CalenderNoteBean.PageBean.ItemsBean listBean : list) {
            if (listBean.endstate == 1) {
                tick1 += 1;
            }
            if (listBean.endstate == 2) {
                tick2 += 1;
            }
        }
        String title_new;
        if (stylee == 0) {
            if (list.size() == 0) {
                title_new = "0";
            } else {
                title_new = tick1 + "/" + list.size();
            }
        } else if (stylee == 4) {
            if (list.size() == 0) {
                title_new = "0";
            } else {
                title_new = tick1 + "/" + tick2 + "/" + list.size();
            }
        } else {
            title_new = list.size() + "";
        }

        return title_new;
    }

    class LoadDataAsyncTask extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(Void... params) {
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
//			dialog.dismiss();
            GenData(true, curDate);
            GenView();
        }

    }

    public ArrayList<HashMap<String, String>> GenData(boolean isfirst, String date) {
        if (!date.equals("") && isfirst) {
            data = new ArrayList<HashMap<String, String>>();
            to_year = Integer.parseInt(date.split("-")[0].toString());
            to_month = Integer.parseInt(date.split("-")[1].toString());
            to_day = Integer.parseInt(date.split("-")[2].toString());
            temp_day = to_day;
            temp_month = to_month;
            temp_year = to_year;
            standard_day = to_day;
            standard_month = to_month;
            standard_year = to_year;
            today = date;
            title.setText(standard_year + "年" + standard_month + "月");
        } else {
            if (isfirst) {
                data = new ArrayList<HashMap<String, String>>();
                Calendar c = Calendar.getInstance();
                c.setTimeInMillis(System.currentTimeMillis());
                to_year = c.get(Calendar.YEAR);
                to_month = c.get(Calendar.MONTH);
                to_day = c.get(Calendar.DAY_OF_MONTH);

                to_month++;
                temp_day = to_day;
                temp_month = to_month;
                temp_year = to_year;
                standard_day = to_day;
                standard_month = to_month;
                standard_year = to_year;

                today = to_year + "-"
                        + (to_month > 9 ? "" + to_month : "0" + to_month) + "-"
                        + (to_day > 9 ? "" + to_day : "0" + to_day);
                title.setText(standard_year + "年" + standard_month + "月");
            } else {
                data = new ArrayList<HashMap<String, String>>();
                temp_day = standard_day;
                temp_month = standard_month;
                temp_year = standard_year;

            }
        }
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("day", temp_day + "");

        map.put("isMonth", "1"); // 1是本月
        String tempStrT = temp_year + "-"
                + (temp_month > 9 ? "" + temp_month : "0" + temp_month) + "-"
                + (temp_day > 9 ? "" + temp_day : "0" + temp_day);
        if ("".equals(StringUtils.getIsStringEqulesNull(tempStrT))) {
            tempStrT = today;
        }
        if (today.equals(tempStrT)) {
            map.put("isToday", "1"); // 1是今天
            map.put("time", today);
        } else {
            map.put("isToday", "0"); // 1是今天
            map.put("time", tempStrT);
        }
        try {
            if (CalHoliday(Integer.valueOf(temp_month
                    + (temp_day > 9 ? "" + temp_day : "0" + temp_day)))) {
                map.put("lunar", holiday);
            } else {
                map.put("lunar", CalendarChange.CalendarChange(tempStrT));
            }
            if (isRed) {
                map.put("isHoliday", "1"); // 1节日
                isRed = false;
            } else {
                map.put("isHoliday", "0"); // 1节日
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        data.add(map);
        for (int i = temp_day - 1; i > 0; i--) {
            String tempStr = temp_year + "-"
                    + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                    + "-" + (i > 9 ? "" + i : "0" + i);
            map = new HashMap<String, String>();
            map.put("day", i + "");
            map.put("time", tempStr);
            map.put("isToday", "0"); // 1是今天
            map.put("isMonth", "1"); // 1是本月
            try {
                if (CalHoliday(Integer.valueOf("" + temp_month
                        + (i > 9 ? "" + i : "0" + i)))) {
                    map.put("lunar", holiday);
                } else {
                    map.put("lunar", CalendarChange.CalendarChange(tempStr));
                }
                if (isRed) {
                    map.put("isHoliday", "1"); // 1节日
                    isRed = false;
                } else {
                    map.put("isHoliday", "0"); // 1节日
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            data.add(0, map);
        }
        int te_week = calWeek(temp_year, temp_month, 1);
        if (temp_month == 1) {
            temp_year--;
            temp_month = 12;
        } else {
            temp_month--;
        }
        calLeapYear(temp_year);
        if (temp_month == 4 || temp_month == 6 || temp_month == 9
                || temp_month == 11) {
            for (int i = 30; i > 30 - te_week; i--) {
                String tempStr = temp_year + "-"
                        + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                        + "-" + (i > 9 ? "" + i : "0" + i);
                map = new HashMap<String, String>();
                map.put("day", i + "");
                map.put("time", tempStr);
                map.put("isToday", "0"); // 是今天
                map.put("isMonth", "0"); // 1是本月
                try {
                    if (CalHoliday(Integer.valueOf("" + temp_month
                            + (i > 9 ? "" + i : "0" + i)))) {
                        map.put("lunar", holiday);
                    } else {
                        map.put("lunar", CalendarChange.CalendarChange(tempStr));
                    }
                    if (isRed) {
                        map.put("isHoliday", "1"); // 1节日
                        isRed = false;
                    } else {
                        map.put("isHoliday", "0"); // 1节日
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                data.add(0, map);
            }
        } else if (temp_month == 2) {
            if (isLeap) {
                for (int i = 29; i > 29 - te_week; i--) {
                    String tempStr = temp_year
                            + "-"
                            + (temp_month > 9 ? "" + temp_month : "0"
                            + temp_month) + "-"
                            + (i > 9 ? "" + i : "0" + i);
                    map = new HashMap<String, String>();
                    map.put("day", i + "");
                    map.put("time", tempStr);
                    map.put("isToday", "0"); // 1是今天
                    map.put("isMonth", "0"); // 1是本月
                    try {
                        if (CalHoliday(Integer.valueOf("" + temp_month
                                + (i > 9 ? "" + i : "0" + i)))) {
                            map.put("lunar", holiday);
                        } else {
                            map.put("lunar",
                                    CalendarChange.CalendarChange(tempStr));
                        }
                        if (isRed) {
                            map.put("isHoliday", "1"); // 1节日
                            isRed = false;
                        } else {
                            map.put("isHoliday", "0"); // 1节日
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    data.add(0, map);
                }
            } else {
                for (int i = 28; i > 28 - te_week; i--) {
                    String tempStr = temp_year
                            + "-"
                            + (temp_month > 9 ? "" + temp_month : "0"
                            + temp_month) + "-"
                            + (i > 9 ? "" + i : "0" + i);
                    map = new HashMap<String, String>();
                    map.put("day", i + "");
                    map.put("time", tempStr);
                    map.put("isToday", "0"); // 1是今天
                    map.put("isMonth", "0"); // 1是本月
                    try {
                        if (CalHoliday(Integer.valueOf("" + temp_month
                                + (i > 9 ? "" + i : "0" + i)))) {
                            map.put("lunar", holiday);
                        } else {
                            map.put("lunar",
                                    CalendarChange.CalendarChange(tempStr));
                        }
                        if (isRed) {
                            map.put("isHoliday", "1"); // 1节日
                            isRed = false;
                        } else {
                            map.put("isHoliday", "0"); // 1节日
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    data.add(0, map);
                }
            }
        } else {
            for (int i = 31; i > 31 - te_week; i--) {
                String tempStr = temp_year + "-"
                        + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                        + "-" + (i > 9 ? "" + i : "0" + i);
                map = new HashMap<String, String>();
                map.put("day", i + "");
                map.put("time", tempStr);
                map.put("isToday", "0"); // 1是今天
                map.put("isMonth", "0"); // 1是本月
                try {
                    if (CalHoliday(Integer.valueOf("" + temp_month
                            + (i > 9 ? "" + i : "0" + i)))) {
                        map.put("lunar", holiday);
                    } else {
                        map.put("lunar", CalendarChange.CalendarChange(tempStr));
                    }
                    if (isRed) {
                        map.put("isHoliday", "1"); // 1节日
                        isRed = false;
                    } else {
                        map.put("isHoliday", "0"); // 1节日
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                data.add(0, map);
            }
        }
        if (temp_month == 12) {
            temp_year++;
            temp_month = 1;
        } else {
            temp_month = temp_month + 1;
        }
        calLeapYear(temp_year);
        if (temp_month == 4 || temp_month == 6 || temp_month == 9
                || temp_month == 11) {
            for (int i = to_day + 1; i <= 30; i++) {
                String tempStr = temp_year + "-"
                        + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                        + "-" + (i > 9 ? "" + i : "0" + i);
                map = new HashMap<String, String>();
                map.put("day", i + "");
                map.put("time", tempStr);
                map.put("isToday", "0"); // 1是今天
                map.put("isMonth", "1"); // 1是本月
                try {
                    if (CalHoliday(Integer.valueOf("" + temp_month
                            + (i > 9 ? "" + i : "0" + i)))) {
                        map.put("lunar", holiday);
                    } else {
                        map.put("lunar", CalendarChange.CalendarChange(tempStr));
                    }
                    if (isRed) {
                        map.put("isHoliday", "1"); // 1节日
                        isRed = false;
                    } else {
                        map.put("isHoliday", "0"); // 1节日
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                data.add(map);
            }
        } else if (temp_month == 2) {
            if (isLeap) {
                for (int i = to_day + 1; i <= 29; i++) {
                    String tempStr = temp_year
                            + "-"
                            + (temp_month > 9 ? "" + temp_month : "0"
                            + temp_month) + "-"
                            + (i > 9 ? "" + i : "0" + i);
                    map = new HashMap<String, String>();
                    map.put("day", i + "");
                    map.put("time", tempStr);
                    map.put("isToday", "0"); // 是今天
                    map.put("isMonth", "1"); // 1是本月
                    try {
                        if (CalHoliday(Integer.valueOf("" + temp_month
                                + (i > 9 ? "" + i : "0" + i)))) {
                            map.put("lunar", holiday);
                        } else {
                            map.put("lunar",
                                    CalendarChange.CalendarChange(tempStr));
                        }
                        if (isRed) {
                            map.put("isHoliday", "1"); // 1节日
                            isRed = false;
                        } else {
                            map.put("isHoliday", "0"); // 1节日
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    data.add(map);
                }
            } else {
                for (int i = to_day + 1; i <= 28; i++) {
                    String tempStr = temp_year
                            + "-"
                            + (temp_month > 9 ? "" + temp_month : "0"
                            + temp_month) + "-"
                            + (i > 9 ? "" + i : "0" + to_day);
                    map = new HashMap<String, String>();
                    map.put("day", i + "");
                    map.put("time", tempStr);
                    map.put("isToday", "0"); // 是今天
                    map.put("isMonth", "1"); // 1是本月
                    try {
                        if (CalHoliday(Integer.valueOf("" + temp_month
                                + (i > 9 ? "" + i : "0" + i)))) {
                            map.put("lunar", holiday);
                        } else {
                            map.put("lunar",
                                    CalendarChange.CalendarChange(tempStr));
                        }
                        if (isRed) {
                            map.put("isHoliday", "1"); // 1节日
                            isRed = false;
                        } else {
                            map.put("isHoliday", "0"); // 1节日
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    data.add(map);
                }
            }
        } else {
            for (int i = to_day + 1; i <= 31; i++) {
                String tempStr = temp_year + "-"
                        + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                        + "-" + (i > 9 ? "" + i : "0" + i);
                map = new HashMap<String, String>();
                map.put("day", i + "");
                map.put("time", tempStr);
                map.put("isToday", "0"); // 是今天
                map.put("isMonth", "1"); // 1是本月
                try {
                    if (CalHoliday(Integer.valueOf("" + temp_month
                            + (i > 9 ? "" + i : "0" + i)))) {
                        map.put("lunar", holiday);
                    } else {
                        map.put("lunar", CalendarChange.CalendarChange(tempStr));
                    }
                    if (isRed) {
                        map.put("isHoliday", "1"); // 1节日
                        isRed = false;
                    } else {
                        map.put("isHoliday", "0"); // 1节日
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                data.add(map);
            }
        }
        if (temp_month >= 12) {
            temp_year++;
            temp_month = 1;
        } else {
            temp_month++;
        }
        int mm = data.size();
        for (int i = 1; i <= 42 - mm; i++) {
            String tempStr = temp_year + "-"
                    + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                    + "-" + (i > 9 ? "" + i : "0" + i);
            map = new HashMap<String, String>();
            map.put("day", i + "");
            map.put("time", tempStr);
            map.put("isToday", "0"); // 是今天
            map.put("isMonth", "0"); // 1是本月
            try {
                if (CalHoliday(Integer.valueOf("" + temp_month
                        + (i > 9 ? "" + i : "0" + i)))) {
                    map.put("lunar", holiday);
                } else {
                    map.put("lunar", CalendarChange.CalendarChange(tempStr));
                }
                if (isRed) {
                    map.put("isHoliday", "1"); // 1节日
                    isRed = false;
                } else {
                    map.put("isHoliday", "0"); // 1节日
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            data.add(map);
        }
        return data;
    }

    public boolean CalHoliday(int t) {
        boolean is = false;
        switch (t / 100) {
            case 2:
                if (t == solartime[0]) {
                    holiday = "立春";
                    is = true;
                } else if (t == solartime[1]) {
                    holiday = "雨水";
                    is = true;
                }
                break;
            case 3:
                if (t == solartime[2]) {
                    holiday = "惊蛰";
                    is = true;
                } else if (t == solartime[3]) {
                    holiday = "春分";
                    is = true;
                }
                break;
            case 4:
                if (t == solartime[4]) {
                    holiday = "清明";
                    is = true;
                } else if (t == solartime[5]) {
                    holiday = "谷雨";
                    is = true;
                }
                break;
            case 5:
                if (t == solartime[6]) {
                    holiday = "立夏";
                    is = true;
                } else if (t == solartime[7]) {
                    holiday = "小满";
                    is = true;
                }
                break;
            case 6:
                if (t == solartime[8]) {
                    holiday = "芒种";
                    is = true;
                } else if (t == solartime[9]) {
                    holiday = "夏至";
                    is = true;
                }
                break;
            case 7:
                if (t == solartime[10]) {
                    holiday = "小暑";
                    is = true;
                } else if (t == solartime[11]) {
                    holiday = "大暑";
                    is = true;
                }
                break;
            case 8:
                if (t == solartime[12]) {
                    holiday = "立秋";
                    is = true;
                } else if (t == solartime[13]) {
                    holiday = "处暑";
                    is = true;
                }
                break;
            case 9:
                if (t == solartime[14]) {
                    holiday = "白露";
                    is = true;
                } else if (t == solartime[15]) {
                    holiday = "秋分";
                    is = true;
                }
                break;
            case 10:
                if (t == solartime[16]) {
                    holiday = "寒露";
                    is = true;
                } else if (t == solartime[17]) {
                    holiday = "霜降";
                    is = true;
                }
                break;
            case 11:
                if (t == solartime[18]) {
                    holiday = "立冬";
                    is = true;
                } else if (t == solartime[19]) {
                    holiday = "小雪";
                    is = true;
                }
                break;
            case 12:
                if (t == solartime[20]) {
                    holiday = "大雪";
                    is = true;
                } else if (t == solartime[21]) {
                    holiday = "冬至";
                    is = true;
                }
                break;
            case 1:
                if (t == solartime[22]) {
                    holiday = "小寒";
                    is = true;
                } else if (t == solartime[23]) {
                    holiday = "大寒";
                    is = true;
                }
                break;
        }
        switch (t) {
            case 101:
                holiday = "元旦";
                isRed = true;
                is = true;
                break;
            case 214:
                holiday = "情人节";
                is = true;
                break;
            case 308:
                holiday = "妇女节";
                is = true;
                break;
            case 312:
                holiday = "植树节";
                is = true;
                break;
            case 315:
                holiday = "消费日";
                is = true;
                break;
            case 401:
                holiday = "愚人节";
                is = true;
                break;
            // case 407:
            // holiday="卫生日";
            // is=true;
            // break;
            case 501:
                holiday = "劳动节";
                is = true;
                break;
            case 504:
                holiday = "青年节";
                is = true;
                break;
            // case 512:
            // holiday="护士节";
            // is=true;
            // break;
            // case 513:
            // holiday="助残日";
            // is=true;
            // break;

            case 601:
                holiday = "儿童节";
                is = true;
                break;
            case 605:
                holiday = "世界环境日";
                is = true;
                break;
            case 701:
                holiday = "建党节";
                is = true;
                break;
            case 801:
                holiday = "建军节";
                is = true;
                break;
            case 910:
                holiday = "教师节";
                is = true;
                break;
            case 1001:
                holiday = "国庆节";
                is = true;
                break;
            case 1225:
                holiday = "圣诞节";
                is = true;
                break;
            default:
                // is=false;
                break;
        }

        return is;
    }

    @SuppressWarnings("deprecation")
    public void GenView() {
        dataLinear.removeAllViews();
        mLayoutParamss.weight = 1;
        LayoutInflater lif = LayoutInflater.from(context);
        LinearLayout temp = new LinearLayout(context);
        int size = data.size();
        for (int i = 0; i < size; i++) {
            View convertView = lif.inflate(R.layout.gritem, null);
            TextView time = (TextView) convertView.findViewById(R.id.time);
            TextView lunar = (TextView) convertView.findViewById(R.id.lunar);
            TextView fraction = (TextView) convertView.findViewById(R.id.fraction);
            LinearLayout itemroot = (LinearLayout) convertView.findViewById(R.id.itemroot);
            HashMap<String, String> map = data.get(i);
            if ((i + 1) < size) {
                HashMap<String, String> map2 = data.get(i + 1);
                if (map2.get("lunar").equals("春节")) {
                    map.put("lunar", "除夕");
                }
            }
            if (map.get("isMonth").equals("1"))// 1是本月
            {
                itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity));
                if (map.get("isToday").equals("1"))// 1是今天
                {
                    time.setTextColor(getResources().getColor(R.color.sunday_txt));
                    lunar.setTextColor(getResources().getColor(R.color.sunday_txt));
//                    itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity_jintian));
                } else {
                    itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity));
                }
//                int m = (i + 1) % 7;
//                if (m == 1 || m == 0) {
//                    time.setTextColor(Color.rgb(50, 79, 133));
//                }
                if (map.get("isHoliday").equals("1")) // 节日
                {
                    time.setTextColor(Color.RED);
                }
                itemroot.setTag(R.id.calendar_index, "1");//0其他,1是本月
            } else {
                time.setTextColor(getResources().getColor(R.color.othermonth_txt));
                lunar.setTextColor(getResources().getColor(R.color.othermonth_txt));
                itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity));
                itemroot.setTag(R.id.calendar_index, "0");
            }
            String day = map.get("day");
            String datestr = standard_year + "-" +
                    (standard_month > 9 ? standard_month : "0" + standard_month) + "-" +
                    (day.length() > 1 ? day : "0" + day);
            if (map.get("isMonth").equals("1")) {// 1是本月
                if (App.getDBcApplication().queryISNOTHOLIDAY(datestr).equals("1")) {//休息
                    fraction.setText("休");
                    fraction.setTextColor(getResources().getColor(R.color.sunday_txt));
                } else if (App.getDBcApplication().queryISNOTHOLIDAY(datestr).equals("2")) {//上班
                    fraction.setText("班");
                    fraction.setTextColor(getResources().getColor(R.color.title0));
                } else {
                    fraction.setText("");
                }
            }
            if (!map.get("isMonth").equals("1")) {
                time.setVisibility(View.GONE);
                fraction.setVisibility(View.GONE);
                lunar.setVisibility(View.GONE);
            }
            time.setText(day);
            lunar.setText(map.get("lunar"));
            itemroot.setTag(day);
            itemroot.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    String day = v.getTag().toString();
                    // 0其他,1是本月
                    String calendar_index = v.getTag(R.id.calendar_index).toString();
                    if ("1".equals(calendar_index)) {
                        Intent intent = null;
                        String dateTime = Integer.toString(standard_year)
                                + "-"
                                + (standard_month > 9 ? "" + standard_month
                                : "0" + standard_month) + "-"
                                + (Integer.parseInt(day) > 9 ? day : "0" + day);
                        Message message = new Message();
                        message.what = 9;
                        message.obj = dateTime;
                        handlerrili.sendMessage(message);
                    }
                }
            });
            if ((i + 1) % 7 != 0) {
                temp.addView(convertView, mLayoutParamss);
            } else {
                if (i != 0) {
                    temp.addView(convertView, mLayoutParamss);
                    dataLinear.addView(temp, mLayoutParamss);
                    temp = new LinearLayout(context);
                }
            }
        }
    }

    /*
     * 基姆拉尔森计算公式 QgW4jIbx W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7 /
     *
     * d 天 m 月 y 年 1月2月换算为去年的13 14月计算
     *
     * 基姆拉尔森计算公式的C#的实现 %NfbgJcL_ //y：年，m：月，d：日。在参数都只传入相应的整数
     */
    private int calWeek(int y, int m, int d) {
        int a = 7; // 用来保存计算得到的星期几的整数 Dz>v;%$S-
        if ((m == 1) || (m == 2))// 如果是一月或二月进行换算 uWKc .
        {
            m += 12;
            y--;
        }
        a = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7; // 得到的星期几的整数
        // 
        // 7ehs+GI
        a++;
        if (a == 7) {
            a = 0;
        }
        return a;
    }

    public void calLeapYear(int i) {
        if (i % 100 == 0) {
            if (i % 400 == 0) {
                isLeap = true;
            } else {
                isLeap = false;
            }
        } else {
            if (i % 4 == 0) {
                isLeap = true;
            } else {
                isLeap = false;
            }
        }
    }

    private void downNoteState() {
        if (NetUtil.getConnectState(getApplication()) != NetWorkState.NONE) {
            HttpUtils httpUtils = new HttpUtils(3000);
            RequestParams params = new RequestParams();
            params.addBodyParameter("titleId", maxTitleId);
            params.addBodyParameter("uId", userid);
            params.addBodyParameter("type", "1");
            httpUtils.send(HttpMethod.POST, URLConstants.清单留言状态公开方下行, params, new RequestCallBack<String>() {
                @Override
                public void onSuccess(ResponseInfo<String> responseInfo) {
                    if (!TextUtils.isEmpty(responseInfo.result)) {
                        Gson gson = new Gson();
                        NoteService.downNoteState bean = gson.fromJson(responseInfo.result, NoteService.downNoteState.class);
                        if (bean.status == 0) {
                            List<NoteService.downNoteState.ListBean> list = bean.list;
                            if (list != null) {
                                updateState(list);

                            }
                            HttpUtils httpUtils = new HttpUtils(3000);
                            RequestParams params = new RequestParams();
                            params.addBodyParameter("titleId", maxTitleId);
                            params.addBodyParameter("uId", userid);
                            params.addBodyParameter("type", "1");
                            httpUtils.send(HttpMethod.POST, URLConstants.清单留言公开方状态表删除通知, params, new RequestCallBack<String>() {
                                @Override
                                public void onSuccess(ResponseInfo<String> responseInfo) {
                                }

                                @Override
                                public void onFailure(HttpException e, String s) {
                                }
                            });
                        }
                    }
                }

                @Override
                public void onFailure(HttpException e, String s) {
                }
            });
        }
    }

    private void updateState(List<NoteService.downNoteState.ListBean> list) {
        for (NoteService.downNoteState.ListBean listBean : list) {
            App.getDBcApplication().updateCalenderNoteState(listBean.titleId, listBean.ccId, listBean.states);
            if (mEditTextList.getChildCount() > 0) {
                for (int i = 0; i < mEditTextList.getChildCount(); i++) {
                    CheckBoxC ch = (CheckBoxC) mEditTextList.getChildAt(i).findViewById(R.id.ch);
                    CButton santai = (CButton) mEditTextList.getChildAt(i).findViewById(R.id.santai_button);
                    if (mEditTextList.getChildCount() == list.size()) {
                        if (list.get(i).id == listBean.id) {
                            if (stylee == 0) {
                                ch.setChecked(listBean.states.equals("1") ? true : false);
                            } else if (stylee == 4) {
                                if (listBean.states.equals("0")) {
                                    santai.setBackground(getResources().getDrawable(R.drawable.icon_santai2));
                                } else if (listBean.states.equals("1")) {
                                    santai.setBackground(getResources().getDrawable(R.drawable.icon_santai3));
                                } else {
                                    santai.setBackground(getResources().getDrawable(R.drawable.icon_santai1));
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    private void initBeforeDiaLog(TextView tixing_tv, Map<String, String> mMap) {
        Dialog dialog = new Dialog(context, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(context);
        View more_pop_menu = fac.inflate(R.layout.dialog_naozhongtiqian2, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = getWindowManager().getDefaultDisplay().getWidth();
        dialog.show();
        new MyBeforeOnClick(dialog, more_pop_menu, tixing_tv, mMap);
    }

    Map<Integer, Boolean> map = new HashMap<Integer, Boolean>();
    private LinearLayout ll;
    private TextView tixingcishu_tv;

    int indexti = 0;
    GridBeforeAdapter adapterti = null;

    class MyBeforeOnClick implements OnClickListener {

        private View view;
        private Dialog dialog;
        private GridView before_gridview;
        private LinearLayout detail_close;
        private TextView tixing_tv;

        private String[] befStrings;

        int height;

        boolean beforeFag;
        Map<String, String> mMap;

        public MyBeforeOnClick(Dialog dialog, View view, TextView tixing_tv, Map<String, String> mMap) {
            this.dialog = dialog;
            this.view = view;
            this.mMap = mMap;
            this.tixing_tv = tixing_tv;
            initview();
            initdata();
        }

        private void initview() {
            detail_close = (LinearLayout) view.findViewById(R.id.detail_close);
            ll = (LinearLayout) view.findViewById(R.id.ll);
            tixingcishu_tv = (TextView) view.findViewById(R.id.tixingcishu_tv);
            before_gridview = (GridView) view.findViewById(R.id.before_gridview);
            height = Utils.dipTopx(context, 80);
            befStrings = context.getResources().getStringArray(R.array.before_time);
            tixingcishu_tv.setText("一次提醒");

            detail_close.setOnClickListener(this);
        }

        private void initdata() {
            if (!"".equals(schID) && schID != null) {
                if (1 == isAlarm || 3 == isAlarm) {
                    map.put(0, true);
                } else {
                    map.put(0, false);
                }
                if (isAlarm == 3) {
                    tixingcishu_tv.setText("两次提醒");
                } else {
                    tixingcishu_tv.setText("一次提醒");
                }
                if (beforeType.equals("准时提醒")) {
                    indexti = 0;
                } else if (beforeType.equals("提前5分钟")) {
                    indexti = 1;
                } else if (beforeType.equals("提前15分钟")) {
                    indexti = 2;
                } else if (beforeType.equals("提前30分钟")) {
                    indexti = 3;
                } else if (beforeType.equals("提前1小时")) {
                    indexti = 4;
                } else if (beforeType.equals("提前2小时")) {
                    indexti = 5;
                } else if (beforeType.equals("提前1天")) {
                    indexti = 6;
                } else if (beforeType.equals("提前2天")) {
                    indexti = 7;
                } else if (beforeType.equals("提前1周")) {
                    indexti = 8;
                } else if (beforeType.equals("准时提醒\n提前5分钟")) {
                    indexti = 1;
                } else if (beforeType.equals("准时提醒\n提前15分钟")) {
                    indexti = 2;
                } else if (beforeType.equals("准时提醒\n提前30分钟")) {
                    indexti = 3;
                } else if (beforeType.equals("准时提醒\n提前1小时")) {
                    indexti = 4;
                } else if (beforeType.equals("准时提醒\n提前2小时")) {
                    indexti = 5;
                } else if (beforeType.equals("准时提醒\n提前1天")) {
                    indexti = 6;
                } else if (beforeType.equals("准时提醒\n提前2天")) {
                    indexti = 7;
                } else if (beforeType.equals("准时提醒\n提前1周")) {
                    indexti = 8;
                }
                map.put(indexti, true);
                adapterti = new GridBeforeAdapter(context, befStrings, height, indexti, tixing_tv, tixingcishu_tv, mMap);
                before_gridview.setAdapter(adapterti);

            } else {
                map.put(0, true);
                if (beforeType.equals("准时提醒")) {
                    indexti = 0;
                } else if (beforeType.equals("提前5分钟")) {
                    indexti = 1;
                } else if (beforeType.equals("提前15分钟")) {
                    indexti = 2;
                } else if (beforeType.equals("提前30分钟")) {
                    indexti = 3;
                } else if (beforeType.equals("提前1小时")) {
                    indexti = 4;
                } else if (beforeType.equals("提前2小时")) {
                    indexti = 5;
                } else if (beforeType.equals("提前1天")) {
                    indexti = 6;
                } else if (beforeType.equals("提前2天")) {
                    indexti = 7;
                } else if (beforeType.equals("提前1周")) {
                    indexti = 8;
                } else if (beforeType.equals("准时提醒\n提前5分钟")) {
                    indexti = 1;
                } else if (beforeType.equals("准时提醒\n提前15分钟")) {
                    indexti = 2;
                } else if (beforeType.equals("准时提醒\n提前30分钟")) {
                    indexti = 3;
                } else if (beforeType.equals("准时提醒\n提前1小时")) {
                    indexti = 4;
                } else if (beforeType.equals("准时提醒\n提前2小时")) {
                    indexti = 5;
                } else if (beforeType.equals("准时提醒\n提前1天")) {
                    indexti = 6;
                } else if (beforeType.equals("准时提醒\n提前2天")) {
                    indexti = 7;
                } else if (beforeType.equals("准时提醒\n提前1周")) {
                    indexti = 8;
                }
                map.put(indexti, true);
                adapterti = new GridBeforeAdapter(context, befStrings, height, indexti, tixing_tv, tixingcishu_tv, mMap);
                before_gridview.setAdapter(adapterti);
            }
        }

        @Override
        public void onClick(View v) {
            Animation translateIn0 = new TranslateAnimation(-view.getWidth(), 0, 0, 0);
            Animation translateIn1 = new TranslateAnimation(view.getWidth(), 0, 0, 0);
            translateIn0.setDuration(400);
            translateIn1.setDuration(400);
            switch (v.getId()) {
                case R.id.detail_close:
                    dialog.dismiss();
                    break;
                default:
                    break;
            }
        }
    }

    private void initMap() {
        for (int i = 1; i < 9; i++) {
            if (i == indexti) {
                map.put(i, true);
            } else {
                map.put(i, false);
            }
        }
    }

    private void initMap1() {
        for (int i = 1; i < 9; i++) {
            map.put(i, false);
        }
    }

    int isAlarm = 1;

    public class GridBeforeAdapter extends BaseAdapter {

        private Context context;
        private String[] beforeTime;
        private int height;
        private int lastIndex;
        String str = "一次提醒";
        TextView tixing, tixingcishu_tv;
        Map<String, String> mMap;

        public GridBeforeAdapter(Context context, String[] beforeTime,
                                 int height, int lastIndex, TextView tixing, TextView tixingcishu_tv, Map<String, String> mMap) {
            this.context = context;
            this.beforeTime = beforeTime;
            this.height = height;
            this.lastIndex = lastIndex;
            this.tixing = tixing;
            this.tixingcishu_tv = tixingcishu_tv;
            this.mMap = mMap;
            initMap();
        }

        @Override
        public int getCount() {
            return beforeTime.length;
        }

        @Override
        public Object getItem(int position) {
            return beforeTime[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        public String[] getBeforeTime() {
            return beforeTime;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            View view = convertView;
            ViewWapper viewWapper;
            if (view == null) {
                view = LayoutInflater.from(context).inflate(R.layout.adapter_grid_before_item, null);
                viewWapper = new ViewWapper(view);
                view.setTag(viewWapper);
            } else {
                viewWapper = (ViewWapper) view.getTag();
            }
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT, height);
            LinearLayout before_ll = viewWapper.getBeforLL();
            before_ll.setLayoutParams(params);

            TextView before_tv = viewWapper.getBeforTime();
            TextView before_tv_state = viewWapper.getBeforState();
            String beforTime = beforeTime[position];
            if (str.equals("一次提醒")) {
                str = "准时提醒";
            }
            if (beforTime.equals(str)) {
                before_tv.setText(beforTime);
                before_tv.setTextSize(15);
            } else {
                before_tv.setText(beforTime.split("-")[0]);
                before_tv_state.setText(beforTime.split("-")[1]);
            }

            if (schBeforeTime == 5) {
                map.put(1, true);
            } else if (schBeforeTime == 15) {
                map.put(2, true);
            } else if (schBeforeTime == 30) {
                map.put(3, true);
            } else if (schBeforeTime == 60) {
                map.put(4, true);
            } else if (schBeforeTime == 120) {
                map.put(5, true);
            } else if (schBeforeTime == 24 * 60) {
                map.put(6, true);
            } else if (schBeforeTime == 48 * 60) {
                map.put(7, true);
            } else if (schBeforeTime == 7 * 24 * 60) {
                map.put(8, true);
            } else {
                map.put(0, true);
            }

            before_ll.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (position == 0) {
                        if (map.get(0)) {
                            map.put(position, false);
                        } else {
                            map.put(position, true);
                        }
                    } else {
                        if (position == lastIndex) {
                            if (map.get(position)) {
                                map.put(position, false);
                            } else {
                                map.put(position, true);
                            }
                        } else {
                            initMap1();
                            map.put(position, true);
                        }

                        lastIndex = position;
                    }

                    adapterti.notifyDataSetChanged();

                    int before = 0;
                    if (map.get(0)) {
                        before = 0;
                    }
                    if (map.get(1)) {
                        before = 5;
                    } else if (map.get(2)) {
                        before = 15;
                    } else if (map.get(3)) {
                        before = 30;
                    } else if (map.get(4)) {
                        before = 60;
                    } else if (map.get(5)) {
                        before = 120;
                    } else if (map.get(6)) {
                        before = 24 * 60;
                    } else if (map.get(7)) {
                        before = 48 * 60;
                    } else if (map.get(8)) {
                        before = 7 * 24 * 60;
                    }

                    int select = 0;
                    for (int i = 0; i < beforeTime.length; i++) {
                        if (map.get(i)) {
                            select++;
                        }
                    }

                    if (select == 1) {
                        tixingcishu_tv.setText("一次提醒");
                    } else if (select == 2) {
                        tixingcishu_tv.setText("两次提醒");
                    }

                    if (position == 0) {
                        if (map.get(0)) {
                            if (select == 1) {
                                isAlarm = 1;
                                schBeforeTime = 0;
                            } else if (select == 2) {
                                isAlarm = 3;
                                schBeforeTime = before;
                            }
                        } else {
                            if (select == 1) {
                                isAlarm = 2;
                                schBeforeTime = before;
                            }
                        }
                    } else {
                        if (map.get(position)) {
                            if (select == 1) {
                                isAlarm = 2;
                                schBeforeTime = before;
                            } else if (select == 2) {
                                isAlarm = 3;
                                schBeforeTime = before;
                            }
                        } else {
                            if (select == 1) {
                                isAlarm = 1;
                                schBeforeTime = 0;
                            }
                        }
                    }
                    if (isAlarm == 0 || isAlarm == 1) {
                        beforeType = "准时提醒";
                        isAlarm = 1;
                        //有提前
                    } else if (isAlarm == 2) {
                        isAlarm = 2;
                        if (schBeforeTime == 5) {
                            beforeType = "提前5分钟";
                        } else if (schBeforeTime == 15) {
                            beforeType = "提前15分钟";
                        } else if (schBeforeTime == 30) {
                            beforeType = "提前30分钟";
                        } else if (schBeforeTime == 60) {
                            beforeType = "提前1小时";
                        } else if (schBeforeTime == 120) {
                            beforeType = "提前2小时";
                        } else if (schBeforeTime == 24 * 60) {
                            beforeType = "提前1天";
                        } else if (schBeforeTime == 48 * 60) {
                            beforeType = "提前2天";
                        } else if (schBeforeTime == 7 * 24 * 60) {
                            beforeType = "提前1周";
                        }
                        //准时+提前
                    } else if (isAlarm == 3) {
                        isAlarm = 3;
                        if (schBeforeTime == 5) {
                            beforeType = "准时提醒\n提前5分钟";
                        } else if (schBeforeTime == 15) {
                            beforeType = "准时提醒\n提前15分钟";
                        } else if (schBeforeTime == 30) {
                            beforeType = "准时提醒\n提前30分钟";
                        } else if (schBeforeTime == 60) {
                            beforeType = "准时提醒\n提前1小时";
                        } else if (schBeforeTime == 120) {
                            beforeType = "准时提醒\n提前2小时";
                        } else if (schBeforeTime == 24 * 60) {
                            beforeType = "准时提醒\n提前1天";
                        } else if (schBeforeTime == 48 * 60) {
                            beforeType = "准时提醒\n提前2天";
                        } else if (schBeforeTime == 7 * 24 * 60) {
                            beforeType = "准时提醒\n提前1周";
                        }
                    }
                    copyisAlarm = isAlarm;
                }
            });

            int select = 0;
            for (int i = 0; i < beforeTime.length; i++) {
                if (map.get(i)) {
                    select++;
                }
            }
            if (position == 0) {
                if (map.get(position)) {
                    before_ll.setBackgroundColor(getResources().getColor(R.color.sunday_txt));
                    before_tv.setTextColor(getResources().getColor(R.color.white));
                } else {
                    before_ll.setBackgroundColor(getResources().getColor(R.color.choosedate));
                    before_tv.setTextColor(getResources().getColor(R.color.gongkai_txt));
                }
            } else {
                if (map.get(position)) {
                    before_ll.setBackgroundColor(getResources().getColor(R.color.mingtian_color));
                    before_tv.setTextColor(getResources().getColor(R.color.white));
                    before_tv_state.setTextColor(getResources().getColor(R.color.white));
                } else {
                    before_ll.setBackgroundColor(getResources().getColor(R.color.choosedate));
                    before_tv.setTextColor(getResources().getColor(R.color.gongkai_txt));
                    before_tv_state.setTextColor(getResources().getColor(R.color.gongkai_txt));
                }
            }


            if (select == 1) {
                ll.setVisibility(View.VISIBLE);
                if (map.get(0)) {
                    tixing.setText("(一次提醒)");
                    isAlarm = 1;
                    copyisAlarm = 1;
                } else {
                    if (map.get(position)) {
                        isAlarm = 2;
                        copyisAlarm = 2;
                        tixing.setText("(一次提醒)");
                    }
                }
            } else if (select == 2) {
                ll.setVisibility(View.VISIBLE);
                isAlarm = 3;
                copyisAlarm = 3;
                tixing.setText("(两次提醒)");
            } else {
                map.put(0, true);
                ll.setVisibility(View.VISIBLE);
                tixing.setText("(一次提醒)");
            }
            return view;
        }

        class ViewWapper {

            private View view;
            private LinearLayout before_ll;
            private TextView before_tv;
            private TextView before_state;

            private ViewWapper(View view) {
                this.view = view;
            }

            private LinearLayout getBeforLL() {
                if (before_ll == null) {
                    before_ll = (LinearLayout) view
                            .findViewById(R.id.before_ll);
                }
                return before_ll;
            }

            private TextView getBeforTime() {
                if (before_tv == null) {
                    before_tv = (TextView) view.findViewById(R.id.before_tv);
                }
                return before_tv;
            }

            private TextView getBeforState() {
                if (before_state == null) {
                    before_state = (TextView) view
                            .findViewById(R.id.before_state);
                }
                return before_state;
            }
        }
    }
}
